As described in Iconic Photos:
In the early morning of 17 June 1939, Eugène Weidmann bowed down before the blade of the guillotine, the last person to do so publicly. Weidmann was the last person to be executed before a crowd in France. He had been convicted of multiple kidnappings and murders, including that of a young American socialite...I doubt that public executions ever had a "moralizing effect." I think they've always been part of the bread and circuses that governments provide.
In the days following the execution, the press was especially indignant at the way the crowd had behaved. Paris-Soir denounced the crowd as “disgusting”, “unruly”, “jostling, clamoring, whistling.” Among the sins the lofty paper found unforgivable was the crowd “devouring sandwiches”. More shockingly for the authorities, the unruly crowd delayed the execution beyond the usual twilight hour of dawn, enabling clear photographs — and one short film! — to be taken. The government regretted that public executions which were intended to have a “moralizing effect” now produced “practically the opposite results.” President LeBrun signed an order to hold executions only behind closed doors.
By this time, France was already an anomaly; the proud tradition of macabre spectacle dating back millennia was fast becoming forbidden in the West. Most German states banned public executions in the 1850s. England carried out her last public execution — that of the Fenian agitator Michael Barrett — in 1868, and most of her dominions followed. From then on, momentum was with ban of public executions. Liberal Denmark banned public executions in 1882, and abolished the death penalty altogether in 1933. In 1936, Kentucky became the last American state to ban public executions.