Prison is the place where they have a modicum of community. They have peers. They're not that anxious to escape. Lookit, the biggest problem is that we as a society are not really serious about rehabilitation. Over and over everybody calls our prisons a failure.
Prisons demonstrably fail to rehabilitate the inmates.
But the prisons survive. Prisons survive because they are doing exactly what we pretend we don't want them to do. We unspokenly want prisons to punish people. Prisons are extremely successful at punishing people. They do not fail at that.