Some people have a negative productivity. The cost of having them in society is higher than the benefit.
There are those who are initiate force against others, or damage or steal their property. The majority of people feel that they are better off in a society in which those people are removed or punished, so they are locked up.
More specifically, we incarcerate convicts for five reasons:
Prisons are not designed to be comfortable, loving places. People are there to receive punishment. They are the garbage dump of the community, and it is useful to regard their contents as such.
The only problem with locking people up is that (usually) this involves letting them out again. All prisoners must either be executed, die in prison, or eventually released. It is in the community's interest for released prisoners not to re-offend.
Sometimes age takes care of this. It is in our evolutionary make up for people to mellow with age and if they commit crimes as young people, and are then released when they are old, the chances re-offending are much lower. But this takes a long time to take effect, and the community does normally not have the stomach for locking offenders of less serious crimes up for this long.
Many leftists would have us believe that every person has a key which will turn them into a loving, caring and productive member of society - that all we need do is to pour enough money into touchie-feelie prison programs and the prisoners will be rehabilitated into model members of society. This is naive.
However equally naive is the notion that violent prisons will not make the inmates worse. Putting prisoners in a situation where they are raped or assaulted by those around them, where their life is in danger, and where they are controlled by the most violent criminals around them (either fellow inmates or prison staff) will make them worse.
Locking up a young angry man with attitude, and putting him in an environment where force, beatings, intimidation, rape and bashings is the dominant paradigm, and in which the only way to survive is join the gangs which perpetrate these things is not conducive to rehabilitation. In fact these people are likely to be far worse on their release from prisons than on their entry.
Social workers have recognized this problem but have, as usual, proposed self interested solutions. Setting up an environment where prisoners are guaranteed of safety, can easily choose to remove themselves from threatening situations, and in which their own (albeit) small territory is respected, doesn't seem to feature highly in the social worker's manifesto.
Turning prisons into comfortable holiday camps is counter-productive, but making prisoners safe from those around them is not. Spending less money on social workers, and more more on security and safety would prevent much crime and suffering.
But social worker's solution, it seems, is to populate the prisons with more social workers who can 'liaise' with the prisoners and who can 'understand' at them.
And so the cycle continues.