In premodern societies (as has already been said, these are ostensibly the model for D&D societies) jail wasn't about benign incarceration or social rehabilitation.
Jail was about punishment, pain and torture. The kinds of people that ran these places were sick sociopaths who wanted to hurt...