LONDON — Britain’s government unlawfully imprisoned victims of torture in immigration detention centers, the High Court said Tuesday.

Judge Duncan Ouseley ruled in favor of former detainees and a charity who said the government relied on an unreasonably narrow definition of torture when deciding whether asylum applicants should be detained while their cases were processed.

Government policy says asylum-seekers who can show evidence of torture should only be detained in exceptional circumstances because of the risk they may be harmed by detention.

But a change introduced in September 2016 narrowed the definition of torture to cover only acts committed by state agents or terror groups holding territory, rather than by any individual or group.

The claimants’ lawyers argued that policy had led to many detainees, including victims of trafficking, no longer being recognized as torture victims. The seven claimants included victims of sexual trafficking and a man who had been kidnapped by the Taliban.

The judge ruled that the policy “lacked a rational or evidence basis” and “excludes certain individuals whose experiences of the infliction of severe pain and suffering may indeed make them particularly vulnerable to harm in detention.”

Duncan Lewis Solicitors, which represented five of the former detainees, said the ruling was a reminder to the government that it is “not above the law.”

The firm said that “the policy on torture was just one cog in the machinery by which the Home Office demeans and degrades those most in need of protection.”

The Home Office said in a statement that it was “considering how it can best address the court’s findings.”