The failures cited by Thompson in his decision are comprehensive and grim. ADOC often doesn’t identify and treat prisoners with serious mental-health needs inside the 14 prisons under its control, he wrote. For those it does identify, the department fails to provide enough qualified mental-health workers to treat them with therapy, and instead often “[imposes] disciplinary sanctions on prisoners for symptoms of their mental illness … without regard for the impact of sanctions on their mental health,” Thompson wrote.

“This ruling means that prisoners with mental illness may finally get the treatment they have been denied for so long,” Maria Morris, a senior attorney with the Southern Poverty Law Center, which represented some inmates in the case, said in a statement. “The suffering some of these men and women have endured is excruciating and inhumane. We are pleased Judge Thompson has demanded that the state of Alabama meet its constitutional obligation to provide adequate care.”

Wallace suffered from bipolar disorder and schizophrenia when he took the stand to testify about the system’s shortcomings. He told the court he sometimes heard the voice of his mother telling him to cut his wrists. He had fatally shot her when he was 16 years old, less than two weeks after his release from a mental hospital on a new medication. Wallace showed the judge and the lawyers present his scars.

Prison officials did not take Wallace’s mental-health needs seriously before his death, Thompson described. In a note in his medical records five days before his suicide, a staff member wrote that he was “using crisis cell/threats to get what he wants,” referring to a specialized cell designed to make suicide attempts more difficult. After some of Wallace’s own attempts, officials cited him for disciplinary infractions—which was department policy, according to Thompson—and sometimes placed him in solitary confinement.

Those practices drew sharp criticism from the judge. “Mental-health and correctional professionals have recognized that long-term isolation resulting from segregation, or solitary confinement, has crippling consequences for mental health,” he wrote. Among those quoted by Thompson was Justice Anthony Kennedy, who wrote a major concurring opinion two years ago criticizing the “terrible price” imposed by lengthy periods of isolation.

Wallace was far from the only one in Alabama’s prisons to face these circumstances. About 3,400 prisoners under ADOC’s supervision receive some kind of mental-health treatment, ranging from medication to psychotherapy. That amounts to 20 percent of the state’s prison population. The stigma surrounding mental illness means the true number of prisoners wrestling with symptoms may be even higher.

Nor are the problems restricted to Alabama. The mid-20th century shift from inpatient psychiatric hospitals to outpatient mental-health care allowed many people with mental illnesses to live normal, productive lives. As I reported in 2015, those who fell through the cracks often ended up in the American criminal-justice system, which now effectively serves as the nation’s mental-health system of last resort. American jails alone house an estimated 400,000 people struggling with serious mental illnesses, a population larger than Cleveland, Honolulu, or New Orleans.