The Supreme Court said on Tuesday that a Rastafarian whose dreadlocks were forcibly shaved by prison guards could not sue state employees for money.

In a 6-to-3 vote dividing the court along ideological lines, the majority said federal law did not allow the prisoner, Damon Landor, to sue individual guards in their private capacity for violating his religious beliefs.

Justice Neil M. Gorsuch wrote the majority opinion, saying there were limits to Congress’s power to attach strings to the federal money given to state institutions like the Louisiana prison where Mr. Landor was held. The three liberal justices dissented, warning that the court’s decision would leave few options for state prisoners whose religious rights were violated.

In a statement, Mr. Landor said: “I am disappointed but not defeated. What happened to me violated my faith and my dignity,” and it “should not happen to anyone else.”

The decision was a departure from a series of Supreme Court rulings in recent years that have repeatedly bolstered religious rights. In 2022, the court sided with a Texas death row inmate who wanted his pastor to touch him and pray aloud at the time of his execution. That same year, the court said a high school football coach had a constitutional right to pray at the 50-yard line after his team’s games.

The Trump administration and lawyers for the former inmate, Mr. Landor, had urged the Supreme Court to allow his lawsuit to proceed.

When Mr. Landor reported for a five-month sentence for drug possession in Louisiana, he had not cut his hair for almost two decades, in keeping with his faith. His dreadlocks fell nearly to his knees.

Four months into his term, in 2020, he was transferred to a new prison. He carried with him a copy of a 2017 legal opinion that held that inmates must be allowed to keep their dreadlocks under a federal law protecting prisoners’ religious freedom.

When he pulled out a copy of that decision, a guard threw it in the trash, according to court documents he filed in a later lawsuit.

Two guards then handcuffed Mr. Landor to a chair and forcibly shaved him bald.

He sued the warden and the guards under the Religious Land Use and Institutionalized Persons Act, a federal law that requires states to protect the religious rights of individuals in state institutions. The law requires state and local prisons to accommodate prisoners’ religious rights as a condition of accepting federal money. Under that agreement, prisoners whose rights are violated can sue for “appropriate relief.”

In a separate case, the Supreme Court ruled in 2020 that a related statute from 1993 — the Religious Freedom Restoration Act — permitted individuals to sue to “obtain money damages against federal officials in their individual capacities.”

The question for the justices was whether the language in the two statutes should be read the same way, as allowing people to get money from individual state employees when their rights have been violated.

The Supreme Court found they should not, saying that individual prison officials were not liable because they had not directly accepted the federal funds or expressly consented to a financial arrangement with the federal government.

Under the Constitution, Justice Gorsuch wrote that Congress’s power to spend money could “bind only those who voluntarily and knowingly undertake obligations by agreement with the federal government.”

Allowing such lawsuits to proceed, he warned, could open the door to lawsuits against all sorts of individuals who work for institutions that accept federal funding. If Congress required universities to allow the participation of transgender athletes in women’s sports, he wrote, coaches could be personally sued if they did not go along.

Likewise, he wrote, doctors could face money damages if their medical practices accepted federal funds and they did not follow congressional guidelines on vaccines.

Justice Ketanji Brown Jackson disagreed, saying Congress intended to permit lawsuits against both the government and government officials and had long used its spending powers to hold people accountable “beyond direct recipients of federal funds.”

State prison officials were agents of the state who “wield its power,” she wrote, joined by Justices Sonia Sotomayor and Elena Kagan.

As a result of the court’s decision, Justice Jackson said, prisoners like Mr. Landor who “suffer violations of their religious freedom in state prisons — no matter how blatant — will often be left remediless” and prison officials will have “little incentive to abide by federal law.”

Zack Tripp, one of Mr. Landor’s lawyers, said the court’s decision meant that inmates whose religious rights are violated by state prison officials would have no way to seek damages “no matter how egregious the wrong.”

But he said the court’s opinion had left open a path for Congress to address the issue and “provide a remedy against this kind of gross abuse.”

In a statement, Daniel Mach, the director of the American Civil Liberties Union’s Program on Freedom of Religion and Belief, called the court’s ruling a “blow to religious freedom and the dignity of incarcerated people.” The decision, he said, would make it harder to hold prison officials accountable when they violate the rights of people in their custody.”

At the U.S. Court of Appeals for the Fifth Circuit, the same court that had ruled that the law protected Rastafarian prisoners’ dreadlocks, a three-judge panel “emphatically” condemned Mr. Landor’s treatment. But the judges said they were bound by past precedent that did not allow such litigation against state officials. The statute Mr. Landor relied on was meaningfully different, the panel wrote, and did not authorize his suit.

The full Fifth Circuit declined to rehear the case, but nine judges asked the Supreme Court to provide direction to the lower courts.