> Depending on the kind of damage a given person may do when not in prison, the cost of keeping said person in-prison may be cheaper than the damage they do to society.
This is definitely true. Prison is sometimes justified as "punishment" and sometimes justified as "protection"of the vulnerable. Both approaches have merit and society generally uses both.
However, if you look at the system as a whole, terrible prison conditions are an obstacle to protecting society. As we have seen fit to imprison some people for less than the entire term of their natural life, you will notice that this means we release people. When people who have been abused by a needlessly cruel prison system are released, it is harder for them to re-integrate into society, and much more likely that they will re-offend, perhaps with the assistance of people who they met in prison (often their only resource upon release.)
Unless you are prepared to argue here that substantially all sentences ought to be life sentences (or death sentences) it is thus critical for the project of protecting society that prison is not cruelly abusive. Rest assured that it is still punishment to be locked in a small room! It is altogether unnecessary and counterproductive for you to rot in the small room, to ruin your health with the food, to lose your teeth for lack of basic dental care, to be abused by guards for fun, to be abused by other inmates, or to be raped, but all of this is common. It is especially counterproductive for prisoners to be denied access to means of self-betterment such as reading material, or to have their reading material replaced with rent-a-book tablets charging exorbitant prices, but this too is a trend in some states.
And this is, of course, just a start; there are of course many other inhumane things in US prisons that harm society as a whole, so much so that it is hard to enumerate a meaningful inventory — perhaps you could start with the article linked?
Nor is it in the service of society that prison guards should put a man in a shower and turn on scalding hot water and leave it on until he dies, but it happened to Darren Rainey. Nor is it in the service of protecting society that prison cards should leave a man in a cell, naked, with the floor covered in sewage, but it happened to Trent Taylor, and the guards were afforded qualified immunity.
And most people who are not literally Nazis and have a shred of moral fiber would not say that involuntarily sterilizing women in prison, and lying to them about it and saying they have cancer, is something that protects society, but it was happening in California AS RECENTLY AS 2014 — yes, the year of our lord two thousand and fourteen, that is not a typo. And the next time you start hearing about "private prisons" remember that this was in a state run facility. (Documentary here: https://www.youtube.com/watch?v=IoD7VgFl9EI )