A key plank of Theresa May’s “hostile environment” immigration policy has been declared incompatible with human rights law in a damning ruling handed down at the high court.

The controversial Right to Rent scheme forces private landlords to check the immigration status of tenants and potential tenants. Unlimited fines or even a prison sentence can be levied under the policy to any landlord who rents to undocumented migrants.

In a robust judgement, Mr Justice Spencer said the much-criticised policy was unlawful because it caused landlords to discriminate against British citizens from minority ethnic backgrounds and against foreign nationals who have a legal right to rent.

He found that requiring landlords to check immigration status caused racial discrimination against anyone without a British passport and against ethnic minorities. The judge also said the government had failed to show that the checks had any effect on encouraging undocumented migrants to leave the country.

“MPs who voted for this legislation would be aghast to learn of its discriminatory effect as shown by the evidence,” he added. “In my judgment, the evidence, when taken together, strongly showed not only that landlords are discriminating against potential tenants on grounds of nationality and ethnicity but also that they are doing so because of the scheme.

“It is my view that the scheme introduced by the government does not merely provide the occasion or opportunity for private landlords to discriminate, but causes them to do so where otherwise they would not.”

Critics say the policy must be immediately repealed. “This is a damning judgment on the government’s hostile environment policy,” said the MP Tom Brake. “The court has confirmed that making landlords part of the border force policing apparatus encourages racial discrimination and doesn’t even work. The home secretary must now do the right thing and dump this discriminatory policy.”

Joanna Cherry QC, the SNP spokesperson for justice and home affairs, said: “Today’s judgment in the high court is yet another damming indictment of the failure of Theresa May’s cruel polices as home secretary. Sajid Javid must now undertake a full review and dismantle the unworkable hostile environment policy.”

Adam, a refugee from Sudan, was granted refugee status but was not able to find anywhere to live because, he believes, of the Right to Rent policy. The only place he could find was in a block of flats where there was a lot of criminal activity including drug dealing.

When he complained about it to his neighbours he was so savagely beaten up that he was in hospital for two months with severe injuries to his skull and knees.

“I feel like my life is over,” he said. “All this happened because of the bad accommodation I was forced to be in. The police have told me it’s too dangerous for me to live in that area any more and I’m now in a hostel which is also a very bad place for me. I thought I would be safe in the UK but after this I just want to leave.”

The Home Office’s own research has shown that 25% of landlords would not be willing rent to anyone without a British passport.

The successful challenge to the Right to Rent scheme was brought by the Joint Council for the Welfare of Immigrants (JCWI), with the Equality and Human Rights Commission, the Residential Landlords Association (RLA) and Liberty intervening.

Chai Patel, legal policy director of JCWI, said: “Now that the high court has confirmed that Theresa May’s policy actively causes discrimination, parliament must act immediately to scrap it. But we all know that this sort of discrimination, caused by making private individuals into border guards, affects almost every aspect of public life – it has crept into our banks, hospitals and schools. Today’s judgment only reveals the tip of the iceberg and demonstrates why the hostile environment must be dismantled.”

John Stewart, policy manager for the Residential Landlords Association, said: “Today’s ruling is a damning critique of a flagship government policy. We have warned all along that turning landlords into untrained and unwilling border police would lead to the exact form of discrimination the court has found.”

Lara ten Caten, Liberty solicitor, said: “Today’s victory is another nail in the coffin for the government’s misguided, discriminatory and unworkable hostile environment policy.

“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. Landlords are not border guards. The government must now scrap this shameful scheme and not waste any more taxpayer money on an appeal.”

Chris Norris, director of policy and practice at the National Landlords Association said: “The court ruling confirms the NLA’s argument that this legislation encourages landlords to discriminate based on an individual’s nationality, leading to administrative bias.

“We hope the ruling will force the government to rethink this damaging and unfair policy that makes landlords feel they must behave like border control officers..”

A Home Office spokesperson said: “We are disappointed with the judgment and we have been granted permission to appeal, which reflects the important points of law that were considered in the case. In the meantime, we are giving careful consideration to the judge’s comments.”

Green Party MP Caroline Lucas said: “Right to Rent was always discriminatory by design. Forcing landlords to check tenants’ passports and face criminal sanctions for renting to the wrong person encourages even suspicion of anyone who doesn’t look or sound typically British.”