Ministers like nothing more than playing to the gallery by praising the courage of our armed forces. Our troops may be ill-equipped and over-stretched, but no opportunity is missed to praise their bravery and self-sacrifice.

For sheer hypocrisy of this kind, little can beat the way Gurkhas have been treated. It was graphically illustrated by a high court judge who, in a damning ruling on Tuesday, condemned as unlawful the way Gurkha veterans had been treated, specifically the way they have been refused the right to settle in Britain if they retired before 1997.

The Gurkhas may have fought and risked their lives for Britain in every single armed conflict since the second world war, yet they had failed to demonstrate they had "strong ties" to Britain.

So argued the Home Office with the full backing of the Ministry of Defence. The 1997 cut-off date was decided on the spurious grounds that before that date Hong Kong was the Gurkhas' base. After the former colony was handed back to China, the UK became their base.

For more than 60 years, the Gurkhas have formed a brigade of the British army. the number of veterans prevented from settling here amount to about 2,000.

Mr Justice Blake noted that when the government imposed the 1997 cut-off date, Tony Blair, then prime minister, had stated:

The Gurkhas have served this country with great skill, courage and dignity ... They have made an enormous contribution not just to our armed forces but to the life of ths country ...

David Blunkett, the home secretary, said he was keen to ensure we recognised "their role in the history of our country and the part they played in protecting us". The 13 VCs and many other bravery awards spoke for themselves, Blunkett added.

The judge noted how after the invasion of the Falklands by Argentina and the subsequent conflict, nationality laws were amended and the islanders were entitled to become full British citizens. He continued, referring to the role of the Gurkhas in the Falklands war:

It would be curious if the Home Office had concluded that the islanders themselves who may have stayed put for many years were regarded as having a close enough connection with the United Kingdom but those who risked their lives and limb to bring them their freedom did not. This would seem to irrationally subvert the historic debt that the prime minister and the home secretary spoke of.

One of the reasons why the Gurkha vets were deemed to have insufficiently strong ties with the UK was that, unlike British army soldiers from Commonwealth countries who are generally given indefinite leave to remain here, Gurkhas were discharged in Nepal, their country of origin. Geoff Hoon, the former defence secretary, claimed this was demanded by the Nepalese government. That assertion, said Blake, was misleading. And it was "plain wrong" to suggest, as ministers had done, that Nepal was opposed to Gurkha vets settling in Britain.

The judge exposed what he called the lack of clarity and consistency in the way ministers applied their immigration policy and used their power of discretion. He might have used much stronger language. And the struggle is not over yet. It may not be necessary to "quash the policy itself", he said, just the way it was applied. But it is not only a question of lawfully applying a policy. "Moral debt", as Blake himself suggested, comes into it too.