The U.S. Supreme Court gave a Texas death-row inmate a second chance to avoid the death penalty on Wednesday, ruling in a 6-2 decision that Duane Buck's lawyer had unconstitutionally introduced testimony suggesting he was more likely to be commit future crimes because he is black.

“As an initial matter, this is a disturbing departure from a basic premise of our criminal justice system: Our law punishes people for what they do, not who they are,” Chief Justice John Roberts wrote for the majority. “Dispensing punishment on the basis of an immutable characteristic flatly contravenes this guiding principle.”

A Texas jury found Buck guilty of capital murder for killing his ex-girlfriend and one of her friends in 1995. His case then moved to the sentencing phase to determine whether he would receive the death penalty. In most states with capital punishment, the phase largely consists of jurors weighing aggravating factors, such as previous convictions, against mitigating ones, like a troubled childhood.

Texas, however, includes an additional step before reaching that balancing act. State laws required the jury to decide whether Buck would pose a “continuing threat to society” if he lived. To assure the jury that Buck did not meet the “future dangerousness” threshold for execution, Buck’s lawyer, a public defender named Jerry Guerniot, called two psychologists to the stand.

Both of them testified that Buck was unlikely to commit further acts of violence. But one of them, Walter Quijano, used a seven-point statistical model to make his determination. The fourth factor was race, with black defendants rated as more likely to commit violent acts in the future.

Guerniot called Quijano to the stand and asked him to discuss his statistical factors. “It’s a sad commentary that minorities, Hispanics and black people, are over-represented in the criminal-justice system,” Quijano testified at one point. He did not revise his argument when cross-examined by the state.

“You have determined that the sex factor, that a male is more violent than a female because that’s just the way it is, and that the race factor, black, increases the future dangerousness for various complicated reasons; is that correct?” the prosecutor asked. “Yes,” Quijano replied.

Presenting that testimony to a jury clearly amounted to inadequate assistance of legal counsel, the justices concluded. “No competent defense attorney would introduce such evidence about his own client,” Roberts wrote. Indeed, Guerniot, who no longer handles death-penalty cases, has received intense criticism for his track record when defending clients facing execution.

Race has long played a role in which defendants get the death penalty and which ones don’t, albeit in subtler ways. What made Buck’s case unusual is that the unconstitutional testimony came not from the prosecution, but from a witness called to testify in Buck’s defense. As my colleague Garrett Epps explained when the Court took up Buck’s case in September, this difference trapped the case in the byzantine morass of death-penalty appeals. The Fifth Circuit Court of Appeals first ruled against Buck on procedural grounds in 2006, then rejected his efforts again in 2015 after a Supreme Court ruling on Texas’s appeals system gave him a second bite of the apple.

Justice Clarence Thomas, joined by Justice Samuel Alito, insisted that the Court should have upheld the Fifth Circuit’s interpretation of federal appellate procedure. “Having settled on a desired outcome, the Court bulldozes procedural obstacles and misapplies settled law to justify it,” Thomas complained in his dissent. He also sided with the lower courts’ determination that Buck’s claimed violated of his Sixth Amendment rights had only a minimal affect of the outcome.

The majority of justices conceded those comments amounted to only a brief exchange during the broader sentencing phase. But they also concluded the statements had crossed a constitutional barrier by making Buck’s race an explicit part of the calculus for whether he would live or die. “Some toxins can be deadly in small doses,” Roberts wrote.