I used to work as an advocate taking patient complaints from mental health facilities and other institutions and the state hospitals, forensic units, and jails were the worst. If the place had a psychiatrist they were often denied medication, given the wrong medication, and/or doped up the night before their hearing so that they'd be out of it and look incompetent. Before deinstitutionalization and even the 10 years or so afterwards state hospitals were killing patients either by neglect, or as a result of abuse and there were death investigations because of how frequently this happened. They were not able to cover it up forever. Now some of those , especially the forensic units have been shut down completely.
In the 80s it was quite common for patients to be given a life sentence by default even for a non-violent crime committed as a result of mental illness. There was a time when a judge would turn down their request for release year after year just because he was afraid that they'd do something if they were free to go home. It took alot of legal challenges to change this bias and it really wasn't until the early 90s when people who were court order committed were able to be given a fair hearing and many of them had lived in those places most of their lives!
Even then, there were many incidents of abuse still going on.