Does punishment serve any useful long term purpose? It always seems like punishments that are excessively harsh lead to civil unrest, and punishments that are not harsh enough are thereby render quite useless. So is there a medium at which punishment is a useful tool in society, or is it just an archaic mode of retribution?

There's been lots of interesting philosophical work on punishment, including discussions that defend a retributive account of punishment and discussions that justify punishment on other grounds, for example, deterring future crime. So, if any of those defenses or justifications is correct, then, yes, punishment does serve a useful long term purpose for (depending on the exact account that is correct) the criminal, his or her victim, or the society in which he or she lives. Of the philosophical treatments of the questions you raise, I most highly recommend an Enlightenment thinker who once was widely read but, unfortunately, no longer is: Cesare Beccaria. His short book On Crimes and Punishments (1764) condemned the use of torture, argued for the abolition of capital punishment, and advocated many reforms for the rational and fair administration of law. Beccaria’s ideas about legal and penal reforms, which influenced intellectuals and statesmen throughout Europe and in North America, inspired many...