The American Civil Liberties Union (ACLU) is suing the state of Pennsylvania to seek relief for hundreds of accused criminals who have been deemed mentally ill but haven’t received timely psychiatric treatment in prison, where they await trial.

The ACLU of Pennsylvania, which brought the lawsuit on Wednesday, says that due to an administrative backlog many of the detainees have spent hundreds of days in prison without adequate mental health care.

Mentally ill detainees in Pennsylvania prisons spend an average of 397 days in custody before receiving treatment, representing the longest wait time in the United States, according to the ACLU. Federal requirements state that detainees start receiving treatment no more than seven days after being found by a court to be incompetent to stand trial.

Many of the mentally ill detainees suffer from severe illnesses and their crimes are often minor, according to the ACLU. The case’s lead plaintiff, a schizophrenic identified as J.H., spent 340 days in jail on charges of stealing three peppermint patties, a type of candy.

“These are in some ways the most vulnerable people in society,” said David Gersch, an attorney with Arnold and Porter LLP, a law firm working with ACLU of Pennsylvania on the case.

Such delays "would never happen, except these people are poor and no one cares about them. It’s been going on for years.”

According to Pennsylvania law, if psychiatric treatment can render a detainee fit for trial, he or she may proceed to court. If not, the state must decide whether to release the detainee or commit the person to a mental health institution.

The state sends mentally ill detainees to two facilities, with combined room for 237 people. The facilities are currently full, and at least 174 others are on a waiting list, Gersch said.

To overcome the backlog, Gersch said Pennsylvania could choose to expand its mental health care facilities or drop charges against detainees who do not pose a danger to themselves or others.

“A lot of these people are nonviolent offenders. You don’t want to keep them in the maximum-security facilities. It takes up space for someone who is truly dangerous,” he said.

The ACLU charges that the backlog not only infringes on detainees’ rights, but poses further dangers to their mental health.

Many mentally ill people see their conditions deteriorate because of the stress of imprisonment, the lawsuit states.

J.H., whose alleged theft of the $3 snacks brought him a year behind bars, came out a man changed for the worse, according to the lawsuit.

“J.H.’s mental state has visibly deteriorated over the past eleven months in jail,” the suit states. “Prior to his most recent detention, J.H. never displayed hostility, was relatively engaged during conversations, and was willing and able to answer simple questions. Now, he is visibly agitated, hostile, and unable or unwilling to engage in conversation.”

The lack of treatment can also make it impossible for some detainees to participate in their own defense. The suit cites eight cases — one of them that of a person who was identified as Jane Doe and who spent 16 months waiting for transfer from the Philadelphia city jail — who’ve had such an experience.

“Prior to her most recent confinement at the Philadelphia Detention Center, Jane Doe would have discussions with her lawyer about her case,” the suit says.

“For the past year or more, she has refused to discuss the case and instead talks about having aliens and space ships in her body, and about being married to Jesus Christ. She has become much more delusional.”

Pennsylvania’s backlog of mentally ill detainees began in 2012, Gersche said, adding that he is not sure what triggered it.

Kathaleen Gillis, spokeswoman for The Pennsylvania Department of Human Services, which is named as a defendant in the suit, said the backlog began under the state’s former Republican governor, Tom Corbett.

She added that the new administration of Thomas Wolf, a Democrat sworn in this year, is aware of the backlog and is working to fix it. However, said she said she could not comment any further on pending litigation.

"It's not to say they're not doing anything," Gersch said. "But whatever they're doing, it's not working yet."

The suit comes amid a larger national debate on the treatment of mentally ill people in prisons. Many rights advocates contend that prisoners with mental health issues should be sent to care institutions instead of prison.

The issue came to the fore recently after high profile deaths in custody of mentally ill inmates.

One homeless man arrested for trespassing was rendered to the jail complex at Rikers Island in New York City and “baked to death” in a solitary confinement cell in 2014, according to The Associated Press.

The ACLU lawsuit notes two people with mental health issues who died while awaiting trial in a Pennsylvania prison. One committed suicide in 2013 and the other was killed by a cellmate in 2015.