WASHINGTON (Reuters) - States cannot execute prisoners who are incapable of rationally understanding the reasons for their punishment, the U.S. Supreme Court ruled on Wednesday, siding with an Alabama man who has suffered strokes and dementia that wiped out his memory of murdering a police officer in 1985.

FILE PHOTO: A general view of the U.S. Supreme Court building in Washington, U.S., January 22, 2018. REUTERS/Carlos Barria/File Photo

In a 5-3 decision with conservative Chief Justice John Roberts joining the court’s four liberals, the justices threw out an Alabama state court ruling that Vernon Madison, 68, was legally eligible to be executed, directing the lower court to reconsider the case.

The U.S. Constitution’s Eighth Amendment, which bars cruel and unusual punishment, prohibits capital punishment for those who, because of dementia, mental illness or other disorders, cannot understand why they will be put to death, the justices ruled.

Madison shot Julius Schulte, a police officer in Mobile, twice in the back of the head as Schulte supervised Madison’s move out of his former girlfriend’s house, court papers said. Madison suffered several strokes in recent years resulting in brain damage, dementia and retrograde amnesia, court papers said. He is legally blind, cannot walk unassisted and speaks with a slur.

Writing for the court’s majority, liberal Justice Elena Kagan said a state is not barred from administering the death penalty if a prisoner merely forgets committing a crime.

“If Alabama is to execute Madison,” Kagan said from the bench, “the Eighth Amendment requires, and the state must find, that he’ll understand why.”

Madison’s attorney Bryan Stevenson, of the Montgomery, Alabama-based Equal Justice Initiative legal advocacy group, welcomed the decision.

“Prisoners with dementia or severe mental illness are extremely vulnerable, that the court has recognized that they cannot be subject to abusive or cruel treatment under the Eighth Amendment is enormously important if our system is going to function in a humane and just manner,” Stevenson said.

Alabama Attorney General Steve Marshall, a Republican, said he expects the lower court to “once again find that Madison is competent to finally face the justice that he has so far evaded for nearly 34 years.”

‘A MOCKERY OF OUR RULES’

Conservative Justices Samuel Alito, Neil Gorsuch and Clarence Thomas dissented, saying the majority went too far in ruling for Madison because the question the court had been tasked with deciding was limited to the legality of the death penalty for prisoners who forget their crimes.

“What the court has done in this case makes a mockery of our rules,” Alito wrote.

The case forced the high court to come to grips with the increasingly common problem of elderly prisoners suffering from diseases of old age. Many inmates now spend decades on death row. Madison was sentenced to death in 1994.

The Supreme Court had previously imposed some limits on capital punishment for people with intellectual disabilities and mental illnesses. The justices have differed over capital punishment but have shown no indication of taking up the broader question of whether the death penalty itself violates the Constitution.

Justice Brett Kavanaugh, an appointee of President Donald Trump, had not yet joined the court when the case was argued last October, and did not participate in the decision.

Madison, who is black, was sentenced to death in his third trial. His first two convictions were thrown out on appeal for racial discrimination in jury selection and other prosecutorial misconduct.

A federal appeals court ruled in 2017 that Madison cannot be executed, saying the evidence showed he had a serious mental disorder resulting in dementia and believed he did not kill anyone. The justices overturned that ruling, but in 2018 halted his execution and agreed to hear his case.

During the litigation, the justices heard from both Alabama and Madison’s attorneys that severe cognitive decline could preclude a state from executing inmates who cannot understand what was happening to them. But the two sides disagreed on whether Madison understood the circumstances of his execution, with Alabama saying he did and his lawyers saying he did not.