Ashworth Hospital, whose high profile patients include the Moors murderer Ian Brady, has been found in breach of government guidelines for keeping psychiatric patients locked in seclusion, often for weeks at a time.

In a landmark ruling, the Court of Appeal has upheld a legal challenge from a 55-year-old male patient who has been treated by the Merseyside hospital for nearly 10 years. The patient - who changed his name to Colonel Munjaz - claimed staff at Ashworth acted unlawfully by locking him in his room, in one case for 20 days, with only limited association with other people on his ward; and that they failed to follow official codes of practice.

Guidelines state that seclusion should only be used by doctors for short spells to segregate severely disturbed patients who pose a risk to others, and should not be used as punishment. They are also required to review this treatment every four hours.

But the court last week found that Ashworth was wrong to deviate from the Mental Health Act code of practice by having its own policy of placing patients with long-term behavioural problems in seclusion, and by not carrying out regular reviews. The judges also found that unjustified use of seclusion breached human rights. This will have far-reaching implications for high security hospitals, which will now have to prove, in each case, they are justified in secluding patients.

The court overturned an earlier ruling in Ashworth's favour. The hospital had argued that it was justified in adopting its own confinement policy because of the exceptional psychiatric histories of its patients.

Ashworth said that only a "tiny percentage" of its 400 patients were being held under these conditions, and that those cases were being reviewed in line with the ruling. It was considering the judgment and had "not ruled out" taking the case to the House of Lords.

In a separate ruling, the court of appeal found that Airedale Hospital, in Yorkshire, had also breached official guidelines, over the treatment of patients in its medium secure unit. This followed a complaint from a Mr S, who was kept in seclusion for 12 days. It was found that the hospital should have locked the doors to the ward, to prevent him absconding, instead of putting him in isolation, or should have provided him with a secure bed.

Mind, the mental health charity which backed both cases, said the rulings represented a victory in the battle to uphold the rights of people with mental health problems.

The Independent on Sunday is campaigning for better services for the mentally ill, including those people languishing in secure hospitals because of a lack of beds in less secure units.