“The net has been cast too wide and the effect of the scheme has been to cause landlords to commit nationality and/or race discrimination against those who are perfectly entitled to rent, with the result that they are less able to find homes than (white) British citizens,” the judge said, citing claims from the Joint Council for the Welfare of Immigrants, which brought the case to court.

Mrs. May, who was Britain’s home secretary for six years before becoming prime minister in 2016, has been closely identified with moves to tighten the country’s migration policies. She promised to create “a really hostile environment” for illegal immigration in a 2012 interview with The Daily Telegraph, although her government now prefers to speak of a “compliant environment.”

Measures to achieve that included a poster campaign, with billboards driven on vans across London’s suburbs in the summer of 2013, urging those in the country illegally to “Go home or face arrest.”

The billboards drew widespread criticism and quickly disappeared. But they were followed by the legislation mandating document checks at many key points in daily life, a cultural shift for Britain, which has no mandatory identity card system, unlike many European countries, and has long considered its relative lack of official paperwork a point of national pride.

Criticism of the measures reached a peak last year, when the government had to apologize to Windrush migrants — the name refers to the Empire Windrush, the liner that brought the first large postwar group of arrivals from the West Indies — who had lived legally in Britain for decades but lost their jobs, were denied medical care and even faced the threat of deportation.

Friday’s judgment was “another nail in the coffin for the government’s misguided, discriminatory and unworkable hostile environment policy,” Lara ten Caten, a solicitor with Liberty, a group that campaigns for civil liberties and supported the court challenge, told the BBC.

“While effective immigration control is a legitimate aim for any government, the Home Office must stop outsourcing its discriminatory policies to third parties who are ill-equipped to enforce them but may be slapped with heavy fines and even end up in prison if they don’t,” she added.