An Ontario judge has ordered the federal government to pay $20 million for placing mentally ill inmates in solitary confinement, with the money earmarked to boost mental health supports in correctional facilities.

In a ruling issued this week, Ontario Superior Court Justice Paul Perell said the Correctional Service of Canada violated the charter rights of thousands of inmates who filed a class-action lawsuit against the agency over its use of administrative segregation.

Perell found those who were involuntarily placed in administrative segregation for more than 30 days, or voluntarily for more than 60, experienced a systemic breach of their rights under the Charter of Rights and Freedoms.

"The placement of a seriously mentally ill inmate in administrative segregation goes beyond what is necessary to achieve the genuine and legitimate aim of securing the safety of the institution," he wrote.

"It does not accord with public standards of decency or propriety in the treatment of a mentally ill inmate. It is also unnecessary because there could have been alternative ways less draconian than then equivalent of solitary confinement to address a security concern, and an indeterminate time to resolve a security concern cannot be justified."

Those who were in segregation for less than 30 days can still make claims later in the case.

Compensation for individual members of the class has also not yet been determined and submissions will be heard at a future date.

The judge says the $20 million sum will go to "additional mental health or program resources" in the penal system as well as legal fees.

"For decades, academic research, commissions, inquiries, inquests, court cases, domestic and international organizations, and the correctional investigator have recommended that the Correctional Service change its policies and practices with respect to the treatment of seriously ill inmates placed in administrative segregation," Perell wrote in his ruling.

"The vindication of the class members' charter rights requires that the federal government be directed to do what it ought to have done for decades," he said.

"The funds are to remedy to the harm caused to society which has suffered from the Correctional Service's failure to comply with the charter and also its failure to comply with the spirit of the Corrections and Conditional Release Act and its purpose of rehabilitating mentally ill inmates to return to society rather than worsening their capacity to do so by the harm caused by prolonged solitary confinement."

The Correctional Service of Canada said it is reviewing the decision and declined to comment further.

Administrative segregation is used to maintain security when inmates pose a risk to themselves or others and no reasonable alternative is available.

The practice has faced legal challenges in Ontario and British Columbia, both of which found extended solitary confinement to be unconstitutional because of the absence of a meaningful review process.

Ontario's top court has given Ottawa until April 30 to fix its solitary confinement law, while B.C.'s has extended the deadline to June 17.

The government has pointed to Bill C-83, now before the Senate, which eliminates administrative segregation and replaces it with "structured intervention units" meant to emphasize "meaningful human contact" for inmates and improve their access to programs and services.

However, the bill does not include hard caps on how many days or months inmates can be isolated from the general prison population, and civil liberties organizations have said it does not go far enough.