I edit a journal called the Journal of Forensic Psychology Practice. Through this journal I have discovered the typical profile of a repeat offender (at any age): inadequate self-control, weak anger management, meager problem-solving skills; distrustful of authority, quick to feel misunderstood, hypersensitive to feeling criticized; often approving of misbehavior in others; unhappy relationships with peers, low grades in school. This personality type responds to difficulties with hostility or aggression, and ignores or purposely flouts social customs when a problem arises.
Bottom line, these are people who carry a lot of misery within. Perceived insults or slights will trigger outsized, disproportionately hostile reactions. Such people fail to impose helpful limits from within, so society imposes limits from without: monetary fines, loss of property, imprisonment.
The worst punishment of all for such people is that others in their neighborhood, school, church, town, or even family will disclaim them. This personality type loses social capital: the support and caring of those nearby. Their only social capital is found in others like themselves, so they become part of a group in which everyone feels lousy most of the time. This loss of social capital may occur painfully early -- preschool onward.
No wonder such people turn to drugs to feel better. No wonder they feel triumphant when they annoy, rob, and harm those who have the caring and support that they lack.
One one hand, their neighbors feel a need for protection from these misery-spreading folk, so the neighbors put the miserable ones together in a place called prison. What else is to be done? Is it fair to Mr. or Ms. Good Citizen to leave Mr. or Ms. Misery free to bother others? Is it not justice to punish Mr. or Ms. Misery for spreading their misery?
On the other hand, pooling miserable people in a prison also means making them into a group, with a common adversary for them to hate: law enforcement. Prison guards, police, and so forth take on the job of limiting harmful behavior. Instead of having a life where conflict is continually yielded in favor of loving compromise, the Misery group are given a daily life of battle. In this battle, truth and goodness are sacrificed to the god of winning.
No, prison can't work if the goal is to reduce criminal behavior. Not the way it's set up. In my reading, I see that many prison systems are trying to find better ways than mere adversarial lock-'em-up procedures. But no society will solve its crime problems by building more prisons and imposing stiffer punishments. Nothing changes a miserable person except persistent application of caring. Persistent punishment may limit behavior, but only persistent caring can change it.