Each time Stephanie Peña was placed alone in a prison cell the length and width of a parking spot, she could feel herself losing it.

Ms. Peña, 23 and living with post-traumatic stress and antisocial personality disorders, would recoil from the bloodstained mattress and the feeling of pests crawling over her as she slept. Desperate, she sometimes tried to harm herself just so her guards would let her out.

When New York banned the use of long-term solitary confinement in its prisons and barred the practice entirely for certain people, including mentally ill prisoners like Ms. Peña, it was hailed as a groundbreaking measure that would fundamentally change life behind bars.

But since the law took effect two years ago, prison officials have refused to implement it and have continued to hold incarcerated people with disabilities in solitary and in cells in specialized disciplinary units for most of the day, according to a class-action lawsuit filed on Tuesday in State Supreme Court in Brooklyn.

Ms. Peña is one of hundreds of prisoners who have been held in isolation or in solitary-like conditions for more than 17 hours at a time in violation of the new state law, according to the lawsuit filed by the Legal Aid Society, Disability Rights Advocates and the law firm Winston & Strawn.

“Solitary confinement is extremely harmful for people generally and, of course, for people with disabilities specifically,” said Stefen Short, a lawyer working on behalf of the Prisoners’ Rights Project of the Legal Aid Society. “Really what the agencies are doing here is flouting the will of the Legislature and by extension flouting the will of the people.”