Survivors of torture have won a legal challenge against Home Office rules on asylum seeker detention in the UK.
The government had argued torture could only be carried out by official state agents or terror groups with territory.
But survivors and the charity Medical Justice argued that definition was too narrow and should include victims of trafficking and other abuses.
The Home Office has said it will not appeal against the ruling, which could affect hundreds of cases.
Under official guidelines, people classed as victims of torture should be housed in private accommodation - provided by the government or family members already living in the country - while their asylum claims are processed.
But the court was told that the new definition led to "many" detainees, including victims of trafficking and rape, no longer being recognised as victims of torture and therefore being locked up in detention centres instead.
That was despite doctors submitting evidence of their torture and ill-treatment, the judge was told.
Mr Justice Ouseley ruled that Home Office policy on torture survivors "lacked a rational or evidence basis".
Analysis: Danny Shaw, BBC home affairs correspondent
This ruling will have a profound effect - both symbolically and in practical terms.
It means there's less risk that asylum seekers who come to Britain severely traumatised after being persecuted, abused or trafficked will be detained.
Medical experts say that's hugely important because detention can lead to a deterioration in the mental health of those who've suffered ill treatment before.
It's also a reminder to the Home Office to ensure it acts within the law when it introduces measures, even apparently minor changes, which affect the welfare of people seeking refuge in the UK.
Seven people who had sought sanctuary in Britain after being raped, abused or trafficked were among those detained under the new policy because they were not classed as torture victims.
But the High Court said the Home Office had acted unlawfully, because the new rules excluded people who were vulnerable to harm in detention.
Mr Po, one of the former detainees who was part of the legal challenge, welcomed the decision.
"The policy allowed the Home Office to turn a blind eye to my suffering and the suffering of hundreds of other torture survivors," he said.
"Although I welcome the decision, it is still upsetting that the Home Office, who should protect people like me, rejected me and put me in detention which reminded me of the ordeal I suffered in my country of origin."
Other detainees in the case included:
- A 20-year-old Vietnamese woman, who said she worked from the age of six to pay off her dead parents' debts with a loan shark. Medical Justice said she was repeatedly beaten with sticks, broken bottles and burned with cigarettes before being trafficked to the UK.
- A 21-year-old Afghan man, who said he was kidnapped and recruited by the Taliban at the age of five, beaten with rifle butts, stabbed and thrown off a mountain.
- Two women who say they were subjected to sexual violence, rape and human trafficking for sexual exploitation.
David Isaac, chairman of the Equality and Human Rights Commission, which intervened in the case, said: "This unlawful policy has been scrapped, but the government should now go further and strengthen the human rights protections for people in immigration detention."
The Home Office said it was looking at how best it could consider the court's findings.