A teenager treated at the psychiatric unit at Airedale Hospital should not have been kept in seclusion, the Court of Appeal has ruled.

Lady Justice Hale said the Airedale NHS Trust was not justified in keeping the Bradford man, identified only as

Mr S, in seclusion "from the time it ceased to be a necessary and proportionate response to the risk he presented to others".

The patient's solicitors today said his experiences had been "horrific" and he may now seek compensation. But the hospital trust stood by its decision, saying it was in his best interests and for the welfare of other patients and staff.

Mr S, who was sectioned under the Mental Health Act in 2001, took the trust to the High Court last year but the claim was dismissed. Judgement in that case said hospitals were not obliged to follow the Code of Practice in the Mental Health Act, just to have regard to it.

But the Court of Appeal ruling says hospitals should observe the code unless there is a good reason to depart from it. This has led experts to hail the latest judgement as a landmark case.

The Court of Appeal judgement said Mr S was aged 19 in July 2001 when he was sectioned after committing various offences. He was put in seclusion - kept in a room alone with no human contact - after being hostile and aggressive towards staff.

He had also absconded and doctors discovered that sexual offences of which he had been convicted were more serious than they had thought. The judgement said doctors decided he needed secure accommodation and he should be kept in seclusion until a bed was available or he improved.

Managers made "strenuous efforts" to find him a secure unit place but Mr S was kept in seclusion for 12 days - six of them overnight only - until one was found.

Doug Feery, solicitor for Mr S, said the case marked a major development in mental health law. "His experiences in seclusion were horrific, not only for the fact he was locked there for 12 long days in a hot summer. He was locked in a poorly ventilated room without a toilet and with stark plastic furniture."

Mr Feery said it was especially frightening for Mr S because he was going through a hyper-manic episode and did not know when the seclusion would end.

He said the court had not awarded damages but that did not stop Mr S from making a claim. "It is anticipated that a damages claim will follow," he said.

A spokesman for Airedale NHS Trust said: "The trust remains convinced that the decision taken in July 2001 to seclude Mr S was the correct decision taken in the best interests of Mr S, and in the interests of the safety and welfare of other patients and staff at the hospital.

"The High Court supported that view when this case was originally heard in 2002 and we are disappointed that judgement of the Court of Appeal went against the trust in July of this year."

Mental health charity Mind welcomed the ruling, which upheld their view that hospitals were wrong to disregard the Code of Practice.