The Scottish Police Authority has been ordered to reconsider its decision to block the retirement of two officers involved in the Sheku Bayoh case.
The police watchdog had refused to allow PCs Nicole Short and Alan Paton to retire on medical grounds until it was known if they would face criminal charges as a result of the incident.
But Lord Woolman has ruled the authority's reasons "do not add up".
Mr Bayoh, 31, died in 2015 after being restrained by police in Kirkcaldy.
Evidence uncovered by BBC Scotland has previously raised fresh questions about the way police officers treated Mr Bayoh before he died in their custody.
But the officers involved have always denied any wrongdoing.
The Scottish Police Authority (SPA) has now been given 30 days to reconsider the application to retire on medical grounds from the officers, both of whom are off on long-term sick leave.
In a written judgement, Lord Woolman said: "No one has suggested that the officers are culpable to any degree in respect of the incident. The SPA itself relies on an unspecified involvement.
"It is a mistake to conflate the public interest with matters in which the public has an interest. Decision-makers must ignore public clamour in undertaking their task.
"I conclude that the SPA's reasons do not add up.
"There is an unbridged gap between the alleged involvement of the officers in a high profile incident and the conclusion that it was in the public interest that they should be prevented from retiring.
"The decision was therefore irrational."
The judgement reveals that PC Short, 32, has served with the police for nine years and that a medical assessment of her health concluded she was suffering from post traumatic stress disorder, as well as being "permanently disabled from undertaking the ordinary duties of a police officer".
PC Paton, 44, has received extensive psychological counselling and a psychiatrist supported his retirement on medical grounds after 17 years' service with the force.
Lord Woolman's judgement includes a sworn statement about the incident given by PC Short last year.
The judge said he had included it because, although it was untested by cross-examination, it gave colour and texture to the circumstances from her viewpoint.
'Enormous blow' to the head
On the day of his death Mr Bayoh had taken drugs, including MDMA, which dramatically altered his behaviour, and he became aggressive with a friend.
He later left home with a knife from his kitchen, and neighbours called the police. He had discarded the knife by the time police arrived.
The account of events from PC Short states she she feared "a murder was about to take place" .
The 32-year-old told how she believed colleagues had used CS and PAVA spray on Mr Bayoh but noted that he reacted to it by "laughing and wiping it away from his eyes like it was just water".
PC Short said another colleague again used spray on Bayoh but it continued to have no effect, prompting her to draw her police baton as he allegedly walked towards her.
She continued: "I could hear him behind me and I knew from what he had said and the way he had moved towards me that he was going to hammer me.
"I felt an enormous blow to the back of my head over to the lower right side. I went flying. My feet actually left the ground and I landed on the ground almost at the other side of the road."
PC Short was taken to hospital before returning to Kirkcaldy Police Station.
Questions over custody death
CCTV, other footage and documents obtained by the BBC has previously casts doubt on some of the officers' accounts of the events that led to Mr Bayoh's death.
The investigation included evidence that the first officers on scene escalated the situation instead of trying to defuse it, and evidence that Mr Bayoh's actions were exaggerated in official police documents.
Scottish Police Federation deputy general secretary David Kennedy said: "We welcome the outcome of this judicial review which makes clear these officers suffered significant injury in the execution of their duties and qualify to retire on grounds of ill-health.
"We hope that a decision is made soon by the SPA to allow this.
"We continue to support our members and hope that a date for a fatal accident inquiry or a public inquiry will be made soon.
"It is in the interests of all concerned in these tragic events that the facts are judicially determined."
An SPA spokeswoman said: "The SPA chief executive has reviewed these decisions as instructed by Lord Woolman and in accordance with the SPA's governance arrangements. We cannot comment further at this stage."