WASHINGTON — The Supreme Court ruled Tuesday that immigrants the government has detained and is considering deporting aren’t entitled by law to a bond hearing after six months in detention and then every six months if they’re still being held.

The case is a class-action lawsuit brought by immigrants who’ve spent long periods in custody. The group includes some people facing deportation because they’ve committed a crime and others who arrived at the border seeking asylum.

The San Francisco-based U.S. Court of Appeals for the 9th Circuit had ruled for the immigrants, saying they generally should get bond hearings after six months in detention, and then every six months if they continue to be held. The appeals court said the government must show why they should remain locked up.

But the Supreme Court reversed that decision Tuesday and sided with the Trump administration, which had argued against the ruling, a position also taken by the Obama administration.

The American Civil Liberties Union, which brought the case on behalf of the immigrants, had previously said that about 34,000 immigrants are being detained on any given day in the United States, and 90 percent of immigrants’ cases are resolved within six months. But some cases take much longer.

In the case before the justices, Mexican immigrant Alejandro Rodriguez was detained for more than three years without a bond hearing. He was fighting deportation after being convicted of misdemeanor drug possession and joyriding, and was ultimately released and allowed to stay in the United States.

The case is Jennings v. Rodriguez, 15-1204.