After being blamed for allowing criminals and fare jumpers to ride the regional trains, officials announced Monday that the Bay Area Rapid Transit system will ramp up security in an attempt to prevent attacks like the one that killed Nia Wilson and injured her sister.

Wilson’s death was caused by a system failure but the system wasn’t BART security; it was our criminal court system. Wilson died because we’ve criminalized mental illness, expecting prisons to take the place of community health care.

It’s true that Wilson’s assailant, John Lee Cowell, had a criminal record. In May, he had been paroled on a two-year sentence for second-degree robbery, part of which was served at a state mental facility. From news reports and family statements, it seems he left with inadequate treatment plans and support for his diagnoses of bipolar disorder and schizophrenia.

It’s well known that mentally ill people populate our prisons. Alisa Roth, author of “Insane: America’s Criminal Treatment of Mental Illness,” estimates that more than half of the nation’s 2.2 million prisoners are mentally ill. One study found that as many as 75 percent of incarcerated women are ill.

Approximately 650,000 convicts leave custody every year as Cowell did. Even though departing inmates aren’t guaranteed transitional care, many prisons provide referrals and medications to departing prisoners.

It’s unclear whether these transitional methods are effective, because any assistance they provide is threatened by the challenges of re-entering society — finding employment, housing, transportation and medical and mental health care.

This raises the question of whether incarceration was the proper correction for Cowell. Unquestionably, committing a robbery was violent and unlawful, but a mental health court (a separate, problem-solving tribunal that diverts defendants from incarceration by supervising them in the community where they receive comprehensive mental health treatment and other support) might have saved Wilson by handling her killer’s actions in such a way that he wasn’t exposed to the violence of modern incarceration and was treated.

The problem is that mental health courts are underfunded and handle tiny percentages of the mentally ill defendants in any given jurisdiction.

Selecting people for mental health court is far from standardized, but typically people accused of low-level, nonviolent crimes are favored. While some mental health courts handle defendants accused of violent felonies like Cowell, the people whose recidivism is most important to prevent are often left out of these programs.

Instead, those defendants are sentenced to prison where they are immersed in more violence. BART police couldn’t find the why for Cowell’s attack on the Wilsons but they know what it was; the police chief called it a “prison yard assault.” We know where Cowell learned that.

Statistically, mentally ill people are less likely to perpetrate violence than to be victims of it so simply expanding mental health courts won’t eradicate violence. But incarcerating Cowell may have exacerbated his illness while costing the state almost $150,000 to keep him in custody, money that’s better invested in, say, the California Department of Public Health’s nascent Violence Prevention Initiative. To stop violent crime, we must understand that it isn’t strictly a law enforcement matter but also a public health issue.

Temporarily stationing more cops throughout the BART system has limited potential to stop a cycle of violence emerging on the transit system; it certainly won’t address the source of our public safety issues writ large. We need to re-examine our criminal justice system and expand mental health courts to do that.

Chandra Bozelko and Joseph P. Calderon are 2018 Leading with Conviction fellows with JustLeadershipUSA, an organization that aims to reduce prison populations by half by 2030.