Seven Supreme Court justices unanimously allowed a challenge to the government’s plans to introduce a 12-month residence for legal aid eligibility.

Halfway through what was scheduled to be a two-day hearing, the court ruled that the Lord Chancellor, Michael Gove, did not have the power to bring in the proposed requirement by way of secondary legislation.

The test, introduced in the 2013 consultation paper, Transforming Legal Aid, and due to come into force in the summer, would have meant that applicants would have had to show lawful residence in the country for 12 months.

Amendments had already been forced to exclude members of the armed forces serving overseas, babies under one and asylum seekers.

In 2014 the High Court struck down the test, ruling it to be discriminatory and unlawful. But the Court of Appeal overturned that judgment last year, stating that the restriction was permissible.

John Halford, the solicitor from Bindmans who represented the Public Law Project, which brought the case, said: ‘The British legal system is rooted in two fundamental principles – that all equally enjoy the protection of our laws and all are accountable to our courts.’

But, he said, the Lord Chancellor ‘planned to undermine them by withholding legal aid from those who failed his residence test, leaving them unable to enforce legal rights’.

A Ministry of Justice spokesperson said: ‘We are of course very disappointed with this decision. We will now wait for the full written judgment to consider.’

To implement the measure, Gove will have to include it in a Bill that is debated in Parliament.