The question doesn't really make sense as asked. The entire criminal justice system, almost by definition, revolves around punishment.
Punishment has several different purposes such as deterrence, removal, rehabilitation. I suspect you wanted to ask about why some of these purposes are "better" than others…
Here's a comic explaining this: https://lawcomic.net/guide/?p=60