Of course, a lot of people are lucky and able to navigate our everyday jungle, thrive and blablabla, but they - almost by definition - don't end up in prison, and those who do already - again, almost by definition - have problems.
Underfunded mental health systems inside and outside, piling on more traumatizing experiences here or there ... sure, for some people getting a few years gives them that wake up call, but in general the problem seems to be that the whole police/prison concept is just a shitty bandaid on wounds festering from all kinds of problems (economical, political all of them usually point to psychosocial/cultural issues).
It is well known that levels and frequency of violence vary greatly by facility and by area within each facility. It sounds like you had a bit of luck with your placement. Sadly, this "penalization for survival" also happens regularly in juvenile facilities and schools.