U.S. District Court Judge Lawrence Karlton in Sacramento gave the corrections department time to issue updated policies on the use of both methods but did not ban them.

He offered a range of options on how officials could limit the use of pepper spray and isolation units when dealing with more than 33,000 mentally ill inmates, who account for 28 percent of the 120,000 inmates in California’s major prisons.

The ruling came after the public release of videotapes made by prison guards showing them throwing chemical grenades and pumping large amounts of pepper spray into the cells of mentally ill inmates, some of whom are heard screaming.

“Most of the videos were horrific,” Karlton wrote in his 74-page order.

Prison officials had already promised to make some changes in how much pepper spray they use and how long mentally ill inmates can be kept in isolation, but attorneys representing inmates said those changes did not go far enough.

Karlton gave the state 60 days to work with his court-appointed special master to further revise its policy for using force against mentally ill inmates.

The inmates’ attorneys and witnesses also told Karlton during recent hearings that the prolonged solitary confinement of mentally ill inmates frequently aggravates their condition, leading to a downward spiral.

“He made findings in every area of ongoing constitutional violations,” said Michael Bien, an attorney who represents mentally ill inmates in the long-running class-action lawsuit. “Despite all these years of legal efforts, he found that there needs to be more done.”

Karlton ordered the Department of Corrections and Rehabilitation to develop a plan to keep mentally ill inmates out of segregation units when there is a substantial risk that it will worsen their illness or prompt suicide attempts.

He found that keeping mentally ill inmates in isolation when they have not done anything wrong violates their rights against cruel and unusual punishment. He gave the state 60 days to stop the practice of holding mentally ill inmates in the segregation units simply because there is no room for them in more appropriate housing.

Even before the latest rulings, the hearings before Karlton spurred the department to limit the time that mentally ill inmates spend in isolation units if they have not broken prison rules.

Karlton also ruled that mentally ill inmates cannot be placed in special security housing units unless corrections officials can demonstrate that the isolation will not further harm their mental state.

The state’s practice of housing inmates in the units for years, even decades, prompted a series of widespread inmate hunger strikes and led to two bills being considered in the Legislature this year that would restrict their use.

Finally, Karlton ordered the state to revise its policy for strip-searching mentally ill inmates as they enter and leave housing units.

Bien said he hopes that Karlton’s decision to let the department work out the details of reforms with the court’s special master will encourage the state to make improvements without appealing the order.

Karlton praised Gov. Jerry Brown’s administration for making progress but said the continuing rights violations are proof that he acted properly a year ago when he rejected Brown’s attempt to end court oversight of prison mental health programs.

The 24-year-old lawsuit over the state’s treatment of its mentally ill inmates has prompted sweeping changes in the state prison system, though the latest ruling is limited to excessive use of force and the isolation of mentally ill inmates.

The mental health lawsuit, along with a separate lawsuit over poor medical care, prompted the state to spend billions of dollars for improvements while dramatically realigning its criminal justice system to keep less serious criminals in county jails instead of state prisons.