The pair were denied entry visas despite telling authorities the Taliban regime posed a risk to their “life and limb”.
The man and woman were represented by British lawyers and said they were entitled to immigration leave “by reference” to the British emergency evacuation of civilians from Afghanistan in August 2021 after a Taliban takeover.
But a High Court judge has upheld their challenge to ministers’ refusal to consider their applications under a scheme through which people can be given leave to enter the UK on “compelling compassionate grounds”.
Mrs Justice Lang outlined her decision in a written ruling published on Thursday after considering evidence at a High Court hearing in London in May.
She ruled that the two judges, who live in Afghanistan, could not be identified in media reports of the case.
The judge said Home Secretary Priti Patel must now decide how their bids to enter the UK should be dealt with.
Women protest against Taliban rule in Afghanistan - in pictures
Mrs Justice Lang heard that other “comparator” judges had been given leave under the scheme.
“In my judgment, there was no rational distinction between the comparator judges and the claimants which could justify a grant of [leave] to the comparator judges but not to the claimants,” she said.
“In their work as judges, hearing counter-terrorism and national security cases, they contributed to the UK government’s objectives in Afghanistan to promote the rule of law, and to combat terrorism.
“In doing so, they placed themselves and their families at considerable personal risk. That risk has heightened since the Taliban seized power.
“They and their families are in hiding, but realistically they will be found by the Taliban at some point.
“There is verified evidence that other judges have been summarily executed by the Taliban.”
The two judges also argued they qualified for leave to enter under an Afghan relocation and assistance scheme.
Mrs Justice Lang disagreed with that argument and ruled against them on it.
Barrister Lisa Giovannetti, QC, who led a government legal team, had told her in a written argument that ministers had made decisions they were entitled to make to further the “legitimate objectives” of conducting an evacuation and maintaining immigration control.
Ms Giovannetti said the “executive” was entitled to decide who to evacuate and who to admit to the UK.