Last Thursday, the justice secretary, Chris Grayling, lauded the role of the legal sector in driving the UK's economic growth. "British law has an unrivalled reputation in the world," he trumpeted , "a decision from a UK court carries a global guarantee of impartiality, integrity and enforceability."

At the same time as Grayling was delivering his speech in the gleaming offices of a commercial City law firm, his colleagues in Westminster were publishing the jobseekers (back to work schemes) bill, a piece of emergency legislation whose sole purpose is to make one particular court decision just that little bit less enforceable.

Five weeks ago, the court of appeal quashed the regulations that underpinned the government's Back to Work programme, and which require jobseekers to undertake unpaid work where directed or face the loss of their benefits. While encouraging the unemployed to obtain relevant skills might seem reasonable enough, the reality of the scheme for at least one jobseeker, Cait Reilly, was that she had to give up voluntary work in a museum to stack shelves without pay.

The appeal court unanimously held the regulations were unlawful because the claimants were required to comply with a scheme that had not been clearly set out.

Clarity is one of the basic requirements of the rule of law: simple fairness requires that everyone should know what the law is and how to avoid breaking it. The flip side of this is that it is equally unfair to punish someone for breaking the law, if the law itself doesn't make clear what is required of them. The Jobseekers Act 1995 made this requirement explicit in relation to work schemes and it was on this basis that the court found that the sketchy 2011 regulations failed to pass muster.

Normally, when the government loses a case, the proper course is to appeal rather than rewrite the laws in its own favour. This time, the government decided that it would rather push legislation through parliament than risk paying out to the very same jobseekers that it had forced to work for free. As a spokesman for the DWP explained yesterday: "This legislation will protect taxpayers and make sure we won't be paying back money to people who didn't do enough to find work."

But if you were expecting to find some mechanism in the bill for distinguishing between jobseekers who "didn't do enough to find work" and those who did, you would be looking in vain. The bill is simply a stitch-up, making lawful what the courts have held to be unlawful. In doing so, it plainly undermines another cardinal feature of the rule of law, which is that legislation should be prospective rather than retrospective, described by Lord Bingham as "a rule of simple fairness, a rule which any child would understand". The most notorious retrospective laws are, of course, those which make something criminal which was lawful at the time it was done but, as Thomas Jefferson once noted, retrospective laws "are equally unjust in civil as in criminal cases". This is particularly true in the present case given that it affects some 300,000 jobseekers who would otherwise be entitled to seek compensation for being unlawfully stripped of their benefits. As the House of Lords constitution committee noted on Wednesday, there is "no compelling operational requirement for parliament retrospectively to amend the law" in this case.

Sadly, retrospective laws are not nearly as uncommon in Britain as they should be – the same shameful trick was pulled by Labour in 2008 when the House of Lords ruled that anonymous witnesses were unlawful, and again in 2010 when the supreme court struck down draconian asset-freezing powers.

The resort to retrospective legislation is particularly unappealing in this present case because it involves a class of claimants that the coalition government has wasted no time in portraying as undeserving.

Indeed, you might be forgiven for thinking that the bill was a golden opportunity for Labour to return to principle and express its opposition to anyone being obliged to work without pay. Faced with the prospect of living up to its name, however, Labour chose instead to abstain in the Commons. In any event, the bill's long-term prospects remain unclear as it is now due to be challenged in the supreme court.

It is worth noting that last month's judgment would not have been possible without legal aid for judicial review – two things which the coalition is also keen to restrict in the name of saving the public money. The pound foolishness of the coalition's efforts becomes even clearer when set against its hope that our legal services market can lead the UK out of current economic doldrums. Britain's global reputation for the rule of law does not rest simply on our ability to advise on corporate mergers but on judgments such as that of the court of appeal. It is therefore no use Grayling promoting the integrity of our courts abroad if he and his colleagues aren't prepared to respect their decisions at home. If the coalition wants to keep on selling the golden eggs, in other words, it would do well to stop strangling the goose that lays them.