Making things better in the long run in not really an objective of the justice system, since the mental universe of those running it has no picture of how that could be done. But it may have happened anyway: over the past few thousand years, unusually violent and uncooperative people have been heavily sat on by the authorities, which had to reduce their evolutionary fitness, at least to some degree.
Hanging does that.
If this was the case, it was due to the fact that criminals aren’t entirely formed by environment: crime is moderately heritable. So if you scrag assholes, gradually the population as a whole slowly changes towards a lower genetic tendency to criminality. You get fewer assholes. Whether this has actually happened in a particular population, and to what extent, would depend on the severity and frequency of state punishment, the length of time this pattern existed, and so on. It may or may not have been significant in a particular population, depending on local history – although there is some reason to believe that something like this may been going on for a very long time (human self-domestication). It’s possible that this trend occasionally reversed.
I have no reason to believe that this was planned. If you look at the trend today, you might get the impression that the powers that be are actively trying to increase the fitness of assholes, but I doubt if that is the case. Sure, that’s the effect, but they don’t know enough to do it on purpose.
For example, when the Supremes decided that being sufficiently stupid is a get-out-of-execution card, they weren’t thinking about long-term biological implications. I doubt if they ever do, or can.
A thought experiment: in the light of behavioral genetics, what should you do when it’s clear that one of a pair of identical twins has committed a truly heinous crime – but you don’t know which one?