It's an interesting question.
I was reading a news piece today where the accused in a murder trial was given the diagnosis of schizophrenia. In the comments below the story, people were pretty positive he would get off and be sent to a hospital rather than jail.
It came down to this; jail is a place you pay for your crimes rather than a place to be rehabilitated. For others though, it was simply a safety issue to get this man away from others. In that way, prisons and asylums have shared a need to protect 'us' from 'them'.
Maybe it's about rethinking the current systems and what their goals are/ should be.