The government broke the law by keeping prisoners in jail longer than necessary, judges at the Court of Appeal ruled today.

David Walker, jailed for indecent assault, suffered due to “general and systemic legal failure”, the court concluded.

Handed an indeterminate jail sentence, Mr Walker could not be released from prison without undergoing a parole course which was unavailable in his jail.

His lawyers therefore argued he was subjected to arbitrary detention, an argument treated with sympathy by the judges.

Lord Justice Laws, sitting with Mr Justice Mitting, said it was unjustifiable that an individual could be kept in jail without an assessment of the danger they represent to the public.

A permission to appeal is pending, and the government has been granted a stay on the ruling until that time.

The judgement has been jumped on by campaigners as proof that indeterminate sentences are an example of badly planned and poorly implemented government posturing on crime.

Under the scheme, prisoners are kept in jail until the can demonstrate they are no threat to the public. But today’s case revealed prisoners without means to prove themselves in their prison are being condemned to a potentially limitless period of detention.

More than 3,000 indeterminate sentences have been passed over the last two years, and the government has said a review of the scheme is already under way.