Soon after convicting a young man for possessing an illegal handgun, Ontario Superior Court Judge David Aston developed a “nagging feeling.”

Months later, at Lamar Griffith’s sentencing hearing, this feeling had become reasonable doubt. The judge had fallen into the “trap,” as he put it, “of not seeing the forest for the trees.” Basically, he changed his mind, and so Judge Aston blindsided the barristers by erasing the conviction, entering an acquittal, and setting Mr. Griffith free.

Now, in a highly unusual ruling sure to be scrutinized by any judge who struggles with indecision, the Ontario Court of Appeal has ruled Judge Aston was wrong to acquit. He was still in control of the trial, they found, and had publicly declared two contradictory verdicts. Obviously, he could not sentence a man he believed to be innocent, and so the only solution, a three judge panel has found, was to call a mistrial.

“The judge can change his mind. The question is what is the remedy in such a situation,” said Paul Calarco, lawyer for Mr. Griffith, who now faces a retrial on the weapons charges. “The court said he should declare a mistrial, because the same judge has said ‘guilty’ and ‘not guilty’ on the same evidence.”

The situation is as rare as they come. Judges have over-ruled themselves on things like publication bans, acceptance of expert witnesses, the admission of evidence, and in rare cases the duration of sentences. One New Mexico judge, curiously, threw out the restraining order he briefly imposed against David Letterman based on the complaint of a woman who believed the talk show host was sending her secret messages through the television.

For a judge to openly change his mind on guilt, however, is highly unusual. It cannot happen following an acquittal, which is final. Nor can it happen in a jury trial, in which a judge must defer to their decision. It can only happen following an uncertain conviction by a judge alone. And though mistrials are meant to be among the rarest of legal remedies, courts in general follow the dictate of Felix Frankfurter, the late U.S. Supreme Court judge, who said “Wisdom too often never comes, and so one ought not to reject it merely because it comes late.”

Still, it is not always clear what to do about it. Mr. Calarco argued that Judge Aston was correct to acquit. “It is absolutely essential that we prevent wrongful convictions,” he said. “Heaven knows that we’ve seen far too many in this country. This is one way that a judge can ensure that there is not a wrongful conviction and also act in the most economical way.”

The Court of Appeal disagreed, and cited a case from 1977 that said the removal of a conviction should only be used in “exceptional circumstances.”

‘Wisdom too often never comes, and so one ought not to reject it merely because it comes late’

Mr. Justice Marc Rosenberg, writing for a three-judge panel, said the proper thing to do was declare a mistrial. They declined to reinstate the conviction, and rejected Crown predictions of a flood of convicts seeking to change a judge’s mind, saying they knew of no other similar example.

But Judge Aston had publicly voiced concern about his own conviction, so he could not play the role of impartial trier of fact, the judges found. The trial had to end. These circumstances “gave rise to a question about [the trial judge’s] objectivity, the legitimacy of the decision making and, at the least, was highly contentious,” the court ruled.

The question of Mr. Griffiith’s guilt or innocence was always going to come down to a judgment call based on circumstantial evidence.

It began at a party in northwest Toronto late at night in February, 2011. It had been snowing, then raining. Responding to reports of a fight, an unmarked police van came upon some young men in an alley, whom they ordered to stop. Two did, but Mr. Griffith ran, pursued by an officer, who said he fumbled with his waistband before climbing a fence. Another officer cut him off, tackled him in a puddle, and punched him three times in the face, bloodying his mouth and chipping a tooth. He had nothing illegal in his possession.

Less than 30 minutes later — approximately an hour after it stopped raining — an officer found a loaded 357 Magnum on the snow near the fence Mr. Griffith jumped over. It had a fingerprint and DNA on it. The fingerprint was not a match, and the DNA was untestable. No one saw how it got there. The gun was dry, suggesting it had not been there more than an hour.

Mr. Griffith testified he did not hear police at first, and ran because he feared being assaulted by them, as he believed a friend of his had been. He said he had been adjusting his pants because they fall down without a belt, not because he was ditching a gun.

He faces a retrial on the weapons charges. His acquittal for resisting arrest will stand.