HOUSTON -- An appeals court has overturned the sentence of Texas' longest serving death row inmate, whose attorneys say has languished in prison for more than 45 years because he's too mentally ill to be executed.

Raymond Riles' "death sentence can no longer stand" because the 70-year-old inmate's history of mental illness was not properly considered by jurors, the Texas Court of Criminal Appeals ruled Wednesday.

The decision means Riles' case will be sent back to a Houston courtroom for resentencing.

He was sent to death row in 1976 for fatally shooting John Thomas Henry in 1974 at a Houston car lot following a disagreement over a vehicle. A co-defendant, Herbert Washington, was also sentenced to death, but his sentence was overturned, and he later pleaded guilty to two related charges and was sentenced to 50 and 25 years in prison.

When Riles was tried, state law did not expect jurors to consider mitigating evidence such as mental illness when deciding whether someone should be sentenced to death. The U.S. Supreme Court ruled in 1989 that Texas laws on jury instructions were unconstitutional because they didn't allow intellectual disability or mental illness as mitigating evidence in the punishment phase of a capital murder trial.

But Riles remained in legal limbo because he didn't have legal representation for decades and lower courts failed to enforce the Supreme Court's decision until at least 2007, Jim Marcus, a professor at the University of Texas at Austin School of Law and one of Riles' attorneys, said Thursday.

Inmates like Riles are "housed on death row because their judgment is a sentence of death, but it can't be carried out because they're too mentally ill. In Texas, that means people are left to languish in the Polunsky Unit (the location of Texas' death row), where the conditions are basically solitary confinement," Marcus said.

While prosecutors argued at Riles' trial that he was not mentally ill, several psychiatrists and psychologists testified for the defence that he was psychotic and suffered from schizophrenia. Riles' brother testified that his "mind is not normal like other people. He is not thinking like other people."

"All parties (now) agree that he is mentally ill. The state of Texas has treated him as such for the 45 years he's been on death row," said Thea Posel, an assistant professor at the University of Texas at Austin School of Law and another of Riles' attorneys.

Harris County District Attorney Kim Ogg did not challenge the effort to overturn the death sentence.

"We are glad Texas' highest (criminal) court agreed with prosecutors and defence lawyers that jurors must be able to consider a defendant's mental health history before deciding punishment," Ogg said Thursday.

Ogg's office declined to comment on whether prosecutors will again pursue a death sentence in Riles' case.

Marcus said he thinks Riles will most likely be resentenced to life in prison.

"This would be a very difficult case for Harris County to pursue further because Mr. Riles is so mentally ill, that it's unlikely he would be found competent to stand trial," he said.

If he were to be resentenced to life in prison, he would likely be eligible for release, but any final decision would be made by the Texas Board of Pardons and Paroles, Marcus said.

While the Supreme Court has prohibited the death penalty for individuals who are intellectually disabled, it has not barred such punishment for those with serious mental illness, according to the Death Penalty Information Center.

In 2019, the Texas Legislature considered a bill that would have prohibited the death penalty for someone with severe mental illness. The legislation did not pass.

The state, which during most years executes more inmates than any other state, has not had an execution since July 2020.