A severely mentally ill young man who tried to escape from a psychiatric unit by attempting to burn down a hospital door had an indefinite prison sentence quashed on Wednesday, after a two-year campaign by his mother.

Joe Paraskeva, 22, had his indeterminate sentence for public protection (IPP) changed to a hospital order at a high court appeal, after new evidence from doctors indicated that he was having a psychotic episode when he attempted to set light to the hospital door. The ruling means that he will now be treated as a patient rather than a prisoner.

The case highlights concerns over widespread insensitivity towards people with mental health problems within the criminal justice system, which campaigners say has meant that many mentally ill people have ended up with criminal records rather than receiving medical help.

Paraskeva's family welcomed the decision, but expressed anger that he had to spend over a year in prison, where he received little treatment for his mental health problems, before being transferred to a medical unit.

His mother, Linda Morgan, said her son should never have been sent to prison and called for greater care to be taken to ensure that mental health patients were not criminalised.

"I am so relieved that the judge and the doctors ruled that he should be in hospital," she said after the ruling. Since her son's conviction she had "felt extreme anger and extreme fear", she said. "Sometimes I still can't believe that society can do this to the most vulnerable people."

She realised her son was having a mental health crisis in October 2010, when he started smashing his fist through mirrors at his family home, saying he could no longer bear to look at his own face. Morgan accompanied him to hospital where he was sectioned under the Mental Health Act. Two days later, disturbed and anxious, he tried to escape from the wing by lighting his aerosol deodorant and firing the flame towards the lock. No one was hurt, but staff were said to have been frightened by his behaviour.

Paraskeva pleaded guilty to arson, and in April 2011 was given an IPP, with a minimum requirement of two years in prison, but no maximum limit, which meant, depending on his behaviour, he could be detained for life. Paraskeva, who had no previous convictions, was sent to Chelmsford young offender institution.

"My son admitted himself to a place of safety; he was asking for help and ended up being sent to prison. Something went seriously wrong. He was extremely unwell," Morgan said.

"He shouldn't have been diverted to the criminal justice system. Unfortunately this has happened to a lot of people."

"The experience was horrendous," Morgan said. "He didn't come out of his cell for months and his condition deteriorated, he stopped eating … He is in the proper place now, receiving proper care and treatment."

Summing up, the judge, Lord Justice Gross, said that evidence indicated that "it was highly likely that he was suffering from paranoid schizophrenia at the time of the offence", and ruled that a hospital order was a more appropriate sentence.

After listening to medical evidence detailing significant improvement in Paraskeva's condition, the judge said the test of whether he posed a risk of serious harm to the public hinged on whether or not he continued to take his medication. He ruled that Paraskeva should remain in hospital, with a restriction order, under section 41 of the Mental Health Act, which means he cannot be discharged without the approval of the Ministry of Justice.

Marjorie Wallace, chief executive of the mental health charity Sane, said: "It is shocking that a severely mentally ill 22-year-old man should have been treated as a criminal and detained in prison rather than a psychiatric hospital. Joe Paraskeva was so paranoid, afraid and deluded that for months he isolated himself in his cell, refused visitors including his family and his mental and physical health deteriorated to such an extent that he was too ill to appear in court.

"He is one of thousands of young people who have been shunted into prison due to the failures of psychiatric services to ensure that they receive care and treatment. More than two-thirds of prisoners, even those on remand before sentencing, suffer from two or more mental health conditions. It is a scandal that while numbers in mental hospitals decline, the number of mentally ill people in prison rises. It is time we stopped replacing hospitals with penal institutions."