Execution is often practical, so I'll restrict my response to torture prior to execution.
Public displays of torture before execution has never functioned as a deterrent. There's been a huge amount of extensive study to show that the severity of punishment is at best a tiny factor when choosing to commit the crime, completely washed out by the much larger economic, social, or educational reasons, and in the cases of religious or ideological crimes, public torture actually increases the likelyhood of the crime being commited (the martyr problem).
Public torture instead serves other public purposes, rarely having anything to do with the criminal. States would use this against agents of rival states as a show of force or a direct message to another ruler. Political figures would do it as a show of loyalty (to show zealous conviction) to a policy or political position of their own state, as often seen by both the Prodistants and the Catholics after the reformation. Dan Carlin has a great podcast called 'Painfotainment' that spends a couple hours digging into how public torture became family entertainment across the western world in the middle ages, complete with taking the ***** out and having a picnic to watch the latest criminal get his eyelids cut off. Some sadistic rulers just liked the excuse, such as Vlad the Terrible reportedly eating lunch under his forest of impailed victims. There was a Tipoo in India in the 1700's that used 'roided-out castrated muscle-slaves to perform amazing feats of strength as executioners so he could watch his enemies get their heads crushed or spines ripped with bare hands.
Basically, if the goal is to deter, it doesn't work. If the goal is a sadistic feeling of justice, or a virtue signal of your commitment towards a particular cause, then have at it. ***** Predators are on that list for me.