A teenage boy who brought a High Court challenge over his "prolonged solitary confinement" in detention has won a ruling that his human rights were breached.
The 16-year-old was granted a declaration by a judge that his Article 8 rights - the right to private and family life - were breached at Feltham Young Offender Institution in west London.
But Mr Justice Ouseley rejected a claim his treatment amounted to a breach of human rights laws which prohibit torture and inhuman or degrading treatment or punishment.
The judge announced that young offender institution rules on both "removal from association" - which relates to being kept in a cell and not allowed to mix with others - and education were breached.
He said: "I shall make a declaration that Article 8 was breached because the interference with his rights was not in accordance with the law."
At a hearing in April, the judge was told the boy, whose behaviour is described as "challenging", remained in conditions amounting to solitary confinement for "almost the entirety of his time" at Feltham after being detained in December last year.
His QC said that for "much of the time", the teenager was locked alone in his cell for about 23-and-a-half hours a day.
The judge was told by counsel for the Justice Secretary that although it was accepted there had been "procedural errors" in the boy's case, which were regretted, those errors "should not be conflated with a finding that the substantive regime to which the claimant has been subjected was unlawful".
The Justice Secretary submitted that "the way in which this particular child has been treated does not cross the threshold set" for a breach of Article 3.
The judicial review action was brought on behalf of the child, who is described as having "significant" mental health problems and cannot be named for legal reasons, by the Howard League for Penal Reform.
The Howard League said after the ruling that the boy, referred to as AB, was "isolated in his cell for months on end", and provided with "only very limited access to education".
Chief executive Frances Crook said: "This is an important judgment. The court has declared this boy's isolation for certain periods and the denial of adequate education unlawful because it was against prison rules.
"It is disappointing that the court stopped short of accepting that keeping AB in isolation for over 22 hours a day was degrading and inhuman treatment. We will be seeking to appeal this part of the ruling."
The charity said AB's isolation was declared unlawful by the court for a total of 127 days because the prison failed to comply with its own rules.
Those rules also required that children in prison get at least 15 hours of education a week, it said, but pointed out that AB "had no education at all for the first 55 days at Feltham, and only 15 hours in total in a two-month period before the hearing".
A Ministry of Justice spokeswoman said: "The safety and welfare of young people held in custody is our highest priority. We are grateful for the judge's findings and will consider these carefully.
"We are pleased that the judgment found there has, at all times, been a considered and proper justification for segregation in this case.
"Proportionate and justified segregation is an essential tool to manage offenders who would otherwise pose a significant risk to staff and other prisoners."
Equality and Human Rights Commission chief executive Rebecca Hilsenrath said: "Isolation of this kind has been widely criticised by experts in the field, both in the UK and internationally.
"To lock up a young child with special educational needs for over 23 hours a day with little to no education or exercise is an attack on their rights.
"It is very far removed from an evidence-based strategy to encourage rehabilitation into society. It is simply the wrong thing to do. We welcome today's judgment that this treatment was unlawful."
Mr Justice Ouseley was told by a QC for the Justice Secretary that the boy, who is due for release some time this month, had a history of assaulting prison staff and making "racist taunts", and "poses a very real risk to the good order or discipline" at Feltham.
In his ruling, the judge said the teenager had a "very difficult childhood, suffering emotional and physical abuse and witnessing domestic violence between his parents".
The Justice Secretary conceded that there had been breaches of the rules.
He said the Article 3 dispute was the main issue in the light of those concessions and "the remedial measures being put in place to ensure compliance with the procedural requirements for removal from association and the provision of education".
Dismissing that part of the boy's challenge, he said that "there has at all times been a considered and proper justification for the removal from association" - initially to "protect officers, then to protect officers from AB and AB from inmates whose anger he aroused by shouting abuse..."