The Supreme Court has ruled against immigrants who are seeking their release from long periods of detention while they fight deportation orders.

In two cases decided Monday, the court said that the immigrants, who fear persecution if sent back to their native countries, have no right under a federal law to a bond hearing at which they could argue for their freedom no matter how long they are held.

The justices also ruled 6-3 to limit the immigrants’ ability to band together in court, an outcome that Justice Sonia Sotomayor wrote “will leave many vulnerable noncitizens unable to protect their rights.”

In recent years, the high court has taken an increasingly limited view of immigrants’ access to the federal court system under immigration measures enacted in the 1990s and 2000s.

“For a while, it seemed like the court was going to push back a bit. In extreme cases, it would interpret a statute to allow for as much judicial review as possible,” said Nicole Hallet, director of the immigrants’ rights clinic at the University of Chicago law school. “Clearly now, the court is no longer willing to do that.”

The immigrants who sued for a bond hearing are facing being detained for many months, even years, before their cases are resolved.

The court ruled in the cases of people from Mexico and El Salvador who persuaded Homeland Security officials that their fears are credible, entitling them to further review.

Their lawyers argued that they should have a hearing before an immigration judge to determine if they should be released. The main factors are whether people would pose a danger or are likely to flee — if set free.

Sotomayor wrote the court’s opinion in one case involving Antonio Arteaga-Martinez, who had previously been deported to Mexico. He was taken into custody four years ago and won release while his case wound through the federal courts. His hearing on whether he can remain in the United States is scheduled for 2023.

But Sotomayor wrote that the provision of immigration law that applies to people like Arteaga-Martinez simply doesn’t require the government to hold a bond hearing.

The court, however, left open the issue of the immigrants’ ability to argue that the Constitution does not permit such indefinite detention without a hearing.

Justice Samuel Alito wrote the court’s opinion holding that federal judges can only rule in the case of the immigrants before them, not a class of similarly situated people.

Sotomayor dissented from that decision, joined by Justices Stephen Breyer and Elena Kagan. She wrote that the ability to join together in a class was especially important for people who have no right to a lawyer and “are disproportionately unlikely to be familiar with the U.S. legal system or fluent in the English language.”

The cases are Johnson v. Arteaga-Martinez, 19-896, and Garland v. Aleman Gonzalez, 20-322.