An Ontario judge cited "unduly harsh custodial conditions" in sparing further jail time for a small-time drug dealer who was busted after selling heroin to an undercover police officer.

Robert Duncan served just over 200 days of pretrial custody at the Toronto South Detention Centre (TSDC), according to a judge's decision.

Duncan was on lockdown 38 times, according to a letter from a security manager at the facility that was filed in court and obtained by CBC Toronto. Almost all the lockdowns were due to staffing shortages and 15 of the incidents lasted longer than 24 hours.

"Duncan's time in pretrial custody was qualitatively oppressive and physically detrimental," Justice Katrina Mulligan wrote in her decision allowing Duncan to walk free. Mulligan sentenced Duncan to a fine and probation.

The defence contended that Duncan's pretrial custody should be multiplied at a standard rate — one point five days for every one day served — and that he deserved an additional credit of 56 days, equal to about a year in custody, which Duncan's defence successfully argued was appropriate for his crime.

Mulligan also found Duncan, who suffers from chronic back pain, received "questionable" medical treatment at the detention facility.

"He suffered more than others would or should," she wrote.

Mulligan's decision raises concerns about issues at a new and expensive detention centre that officially opened in 2014, and housed an average of 873 inmates in 2017, according to the province.

Criminal lawyers have told CBC Toronto that the lockdowns have contributed to shorter sentences for inmates, although there are no firm numbers about how often this happens.

Inmate says he was denied medication

The TSDC was the subject of a lengthy expose in Toronto Life magazine last year, while the province also faces a class action lawsuit over frequent lockdowns in detention facilities, including Toronto South.

The Toronto South Detention Centre was opened in 2014, but has been the subject of criticism in recent years. (Nathan Denette/Canadian Press)

In an affidavit obtained by CBC Toronto, Duncan said he experienced "pain and numbness" following an injury in 1999 and was diagnosed with osteoarthritis in his lumbar spine. Duncan also said he was given opioids when other treatments failed.

He said he was denied access to adequate medication while in custody and went through withdrawal in jail.

"Despite having my prescription information from my pharmacy, they would not provide me with my regularly prescribed medication," he wrote.

He said he experienced pain and dizziness, and had trouble sleeping after the first doctor he saw at Toronto South "would not prescribe opiates."

"My level of pain was unbearable."

'Judges are sending a message,' lawyer says

Lawyers contacted by CBC Toronto said lockdowns are a regular occurrence at TSDC, where inmates can be confined to their cells for long stretches.

A view inside the Toronto South Detention Centre. (CBC)

"Can you imagine sitting in a cell with a cellmate who also hasn't showered for five days straight?" said lawyer Ryan Handlarski.

Gina lgbokwe, Duncan's lawyer, said lockdowns can entail restrictions on inmates' abilities to shower, meet with family or lawyers and access the yard.

A spokesperson for Ontario's Ministry of Community Safety and Correctional Services said in an email statement that inmates under lockdown "may still be permitted to attend programs, attend public/professional visits, shower, make telephone calls, etc."

However, the statement continued, "There may be limitations imposed such as restricted movement, program cancellation, etc., depending on the reason for the lockdown."

Now, judges are starting to hand down sentences that acknowledge the stresses of living under lockdown.

Handlarski recently represented a client convicted of drug charges.

The judge granted the defendant an additional four months of credit toward his sentence, acknowledging lockdowns at the TSDC mainly caused by staffing shortages, according to a written decision.

"Judges are sending a message, I think, that you're going to get significant credit … because this is a bad situation," Handlarski said.

"We can't just turn a blind eye to it."

Province won't discuss staffing

Monte Vieselmeyer, chair of the corrections division for the Ontario Public Service Employees Union, said the South is short-staffed.

"I would say we're probably now ... a good 50 to 100 full-time staff behind where we need to be," he said.

A spokesperson for the province said in an email that there are "sufficient staff to run the institution in a safe and secure manner and new staff are added on a regular basis." The spokesperson would not comment on staffing levels in detail, citing unspecified "security reasons."

However, those staff are facing challenges.

There were 138 assaults by inmates on staff at TSDC in 2017, according to provincial statistics.

Sent to segregation

Duncan, who could not be reached for comment, described his time in custody in an affidavit filed in court.

In February, Duncan fell from his bunk and his head was cut open after he drank contraband alcohol. Reports written by responding staff and obtained by CBC Toronto describe Duncan as belligerent, and said he was using racist and misogynistic language before he was taken to hospital.

In his affidavit, Duncan said that after he was treated in hospital, he was escorted in a wheelchair to a van, where jail staff told him to stand. When he said he couldn't, Duncan said detention centre staff lifted him by his arms, but he could not raise his legs.

"The officers then threw me forward into the van, head first, then threw my legs over top of me into the van," Duncan wrote, adding he was left on the floor of the vehicle for the trip back to TSDC.

Upon return, Duncan said he was placed in segregation without a mattress or pillow.

Mulligan cited Duncan's treatment by staff in explaining her decision to side with the defence and spare him further time in custody. Staff's poor handling of Duncan's medical condition, she wrote, combined with lockdowns, "contributed to what can only be described as unduly harsh custodial conditions."

Igbokwe said human rights extend inside detention facilities, even if "jail is not intended to be a great, wonderful place to be."

"At the end of the day, we live in a society that respects basic human rights," she said.