Updated

The Supreme Court ruled Thursday that a state judge was wrong to participate in the case of a death row inmate whose prosecution he personally approved nearly 30 years earlier.

The justices voted 5-3 to hold that the judge violated defendant Terrance "Terry" Williams' constitutional rights by taking part in the Pennsylvania Supreme Court's consideration of Williams' case.

Ronald Castille was the Philadelphia district attorney when he signed off on the death penalty prosecution of Williams in 1986.

Nearly 30 years later, Castille was chief justice of Pennsylvania's top court when it voted unanimously to reinstate Williams' death sentence after a lower court judge had tossed it out.

Castille, now retired, refused defense requests to withdraw from the case.

The Supreme Court ordered a new sentencing hearing for Williams, even though Castille was just one of six votes.

Justice Anthony Kennedy wrote the majority opinion, joined by the court's four liberal justices.

"Chief Justice Castille's participation in Williams' case was an effort that affected the state supreme court's whole adjudicatory framework below," Kennedy wrote.

Chief Justice John Roberts, and Justices Samuel Alito and Clarence Thomas dissented.

Roberts wrote that the court was wrong to rule that the legal maxim "no man can be a judge in his own case" mandated Castille's absence from Williams' case.

"The majority opinion rests on proverb rather than precedent," Roberts wrote.

Williams' death sentence was thrown out in 2012, five days before he was scheduled to be executed.

Williams, who had been a star high school quarterback, was convicted of killing a church deacon. He already had been convicted of killing a high school booster, for which he was sentenced to up to 27 years in prison.

The state judge found that Philadelphia prosecutors had withheld evidence that the deacon was molesting boys. Williams claimed the deacon had sexually abused him for years, although he did not make that allegation at his trial.

Prosecutors described Williams as a vicious double-murderer who at best perjured himself — if the abuse claims are true — when he told jurors he barely knew the church deacon and did not kill him. The married 56-year-old deacon, Amos Norwood, was beaten to death with a tire iron in a cemetery. The earlier victim, 50-year-old Herbert Hamilton, was beaten and stabbed in bed. Both bodies were set on fire.

When Castille's court reinstated Williams' death sentence, Castille wrote that the lawyers and scholars supporting Williams' case were "abolitionists ... trying to figure out ways to overcome the death penalty."

Pennsylvania has not executed anyone since 1999, and Gov. Tom Wolf last year announced a freeze on the death penalty shortly after taking office.