He's been gone for some time, but yesterday marked the formal inglorious end of Chris Grayling's tenure as justice secretary and lord chancellor. The last lingering flap of legislative change Grayling tried to introduce was knocked down: The Supreme Court rejected his plan to introduce a residency test for legal aid.

The plan was typical of Grayling: It was mean, it radically reduced access to justice, and it was passed in a manner intended to avoid scrutiny. It would have meant that anyone trying to get legal aid needed to have been in the UK for 12 months. Or at least, that's how it would have started. Once it was written down in law, it seems likely the requirements would have got longer and longer. The Tories would extend it everytime Ukip had another surge in the polls, a future Labour government would have done so when it needed to look tough on immigration.

Had this policy been implemented, the miscarriages of justice would have been appalling. Take the case of P, an adult with severe learning disabilities. He was regularly beaten by his mother and brother, starved, and kept in a kennel outside the house. It was a legal aid which provided him with the defence in order for him to live separately from his family. But it would have been impossible to ascertain if he met the residence test.

The same would be true for a recent immigrant facing discrimination at work, or an asylum-seeking child left destitute by a local authority dispute over who has responsibility for them. These cases happen all the time. If Grayling had passed his test, they'd have no access to justice at all.

When the case first went before a court back in 2014, lawyers made two arguments: firstly, that it was discriminatory and secondly that it was not within the lord chancellor's power to do. Grayling had taken a legal aid law which was about access to justice and tried to insert a severe restriction to access to justice in it using a statutory instrument.

Statutory instruments are dreadful little legal inventions which vastly expand the powers of government. They mean a secretary of state can make changes to a law without having to actually go to the House of Commons and have a proper debate, as you would for primary legislation. You just slip it right on in there. There are, of course, instances in which statutory instruments are sensible vehicles for minor legislative changes. But you can’t trust the government with anything. They have predictably misused them.

Grayling was always a fan of exercising executive power without scrutiny or opposition. He took control of each prison's disciplinary system from Whitehall, he tried to make judicial review – which allows citizens to take public bodies to court – irrelevant, and he attempted to savagely cut back legal aid. In each case, he strengthened Whitehall and reduced the power of others – be they citizens or prison governors or those on low incomes.

The first time the changes went to court, the ruling was damning. It found that Grayling had tried to introduce changes which ran against the purpose of the Act. The purpose of legal aid legislation which was to provide free legal services to people who need it, not people who happened to be in the right country. "No one can pretend that removing legal aid from non-residents is a means of targeting legal aid at those most in need," Lord Justice Moses concluded. "Within the system provided by [legal aid legislation], the UK is not permitted to discriminate against non-residents on the grounds that to do so might save costs."

Grayling had tried to turn the law into an instrument of discrimination and lost. Unfortunately, that wasn't the end of it. The government won an appeal, so lawyers from the Public Law Project appealed back and the case ended up in the Supreme Court yesterday. 

It was expected to last two days, with a ruling due possibly in June, but perhaps as late as October. Instead, it took hours.

The Supreme Court took the unprecedented step of allowing the appeal halfway through the ruling. There wasn't any reason to look into whether the test was discriminatory, because the court had already decided it was not within the lord chancellor's power to do it at all. The use of a statutory instrument was inappropriate for a legal change which ran against the spirit of the original legislation.

This wasn't just a victory against discriminatory changes to the legal system, but also against these increasingly pernicious legislative devices, which allow the government to sidestep parliament.

Unfortunately, that's probably not the end of the story. It is, of course, no longer Grayling pushing through these changes. It is Michael Gove. And despite generally being keen to reverse his predecessor's actions in office, that's not the case here. Gove has pushed for these changes in exactly the same manner as Grayling did.

The MoJ made clear throughout the build-up to the case that it would pass the changes using primary legislation if it was prevented from doing so using a statutory instrument.

It may not be quite as simple as they imagine, however. Once the EU referendum is out the way – assuming there is a vote for Remain –David Cameron is expected to want to use his remaining two years to cement a liberal, socially-conscious legacy, particularly on criminal justice. The spectacle of a Commons and media debate on residency tests for legal aid would not be useful in that endeavor.

But even if they do go ahead, it will at the very least be properly debated. When a secretary of state wants to introduce discrimination to the legal system, they can come to the Commons and make the case themselves, rather than try to sneak it in through the back door.

Ian Dunt is editor of Politics.co.uk.

The opinions in politics.co.uk's Comment and Analysis section are those of the author and are no reflection of the views of the website or its owners