The Supreme Court ruled Tuesday that immigration officials can continue to indefinitely detain immigrants during proceedings to determine the legality of their status in the U.S.

In the 5-3 decision, which Justice Elena Kagan took no part in, the Supreme Court reversed the 9th Circuit Court of Appeals decision that ruled detained immigrants must receive bond hearings every six months to determine if their continued detainment was necessary.

The decision of Jennings v. Rodriguez affects illegal and legal immigrants. Legal permanent residents facing deportation as a result of committing crimes and asylum seekers who have turned themselves in at the border and are awaiting a court date can be detained indefinitely with no interval bond hearings.

Justice Samuel Alito wrote the majority opinion, which included himself and the other conservative Justices John Roberts, Clarence Thomas, Neil Gorsuch, and Anthony Kennedy.

“Detention during those proceedings gives immigration officials time to determine an alien’s status without running the risk of the alien’s either absconding or engaging in criminal activity before a final decision can be made,” Alito wrote in the majority opinion.

Kagan decided to recuse herself from the case because of work she had done under former President Obama as his solicitor general. Justices Ruth Bader Ginsburg, Stephen Breyer, and Sonia Sotomayor were of the dissenting opinion.

At the ruling, Breyer read from the dissenting opinion, a rare move that likely indicated his strong feelings against the majority opinion in this case, according to NPR.

"Whatever the fiction, would the Constitution leave the Government free to starve, beat, or lash those held within our boundaries?" Breyer argued. "If not, then, whatever the fiction, how can the Constitution authorize the Government to imprison arbitrarily those who, whatever we might pretend, are in reality right here in the United States?" Breyer said, calling the ruling “legal fiction.”

The named plaintiff Alejandro Rodriguez came to the U.S. as an infant and became a lawful permanent resident. The original case was born after Rodriguez had two convictions, one for drug possession and the other for joyriding. The Department of Homeland Security initiated deportation proceedings against him and detained Rodriguez for three years.

Rodriguez's attorney wanted the Supreme Court to decide illegal immigrants have a right to bond hearings.