In May of 2013, Astrid Morataya, a legal permanent resident, woke up to a knock on the door. Looking outside the window, she saw law enforcement agents with bulletproof vests encircling her home in Illinois.

“They must have the wrong house,” she thought. But they were, in fact, there for her. The government waited 15 years to attempt to deport Astrid for a low-level drug conviction that she received in the late ‘90s, during a period in her life when she was the victim of ongoing sexual abuse. Astrid spent the next two-and-a-half years fighting her deportation case behind bars, separated from her three U.S. citizen children. Held in county jails in Illinois and Wisconsin, she was twice placed in solitary confinement. The first time was for having a sugar packet in her uniform that she forgot to dispose of at mealtime, and the other was for not being ready to leave her cell because she had begun menstruating and was trying to obtain menstrual pads.

At no point did Astrid receive a hearing on whether her imprisonment was justified, even though she presented no threat to public safety or to flee. Eventually, she learned that she could apply for a “U visa,” a type of visa for victims of crimes who assist law enforcement, because she had previously testified against her abuser in court.

In November 2015, Astrid was released from detention, after spending more than two years unnecessarily imprisoned. She isn’t alone. Every day the government subjects thousands of immigrants to mandatory detention without the due process of a hearing, based on offenses they committed and served sentences for years ago.

On Oct. 10, the American Civil Liberties Union will argue before the U.S. Supreme Court in a case which could change that. Nielsen v. Preap challenges the government’s sweeping interpretation of a 1996 mandatory detention law, which requires that certain people are detained for the duration of their deportation proceedings — without a hearing — because they have past criminal records.

Here’s what you need to know.

What is mandatory detention and why do we do it?

Congress passed the mandatory detention law in 1996 to crack down on immigrants with certain criminal histories, based on the notion that “criminal aliens” as a group were reoffending and failing to appear in court. The law requires the government to lock up people without a hearing until their deportation case is resolved, based on their criminal histories. No similar rule applies when people are accused of crimes and awaiting trial. As a result, many people are jailed even though an immigration judge would find that they do not pose a threat to the community or flight risk.

The mandatory detention law was a draconian response to an imaginary problem. There is no evidence that mandatory detention is needed to protect public safety. Instead of keeping dangerous criminals off the street, the law overwhelmingly has jailed people with minor and nonviolent offenses — like marijuana possession, shoplifting, or traffic offenses. And in many cases — like Astrid’s — the person is found to be legally entitled to live in the United States and is not deported.

What is the ACLU challenging?

Unfortunately, when it comes to mandatory detention, the government has taken a truly bad law and made it much worse. Through a sweeping interpretation of the law’s language, the government has expanded mandatory detention far beyond what Congress intended, locking people like Astrid up years or even decades after they served sentences or rehabilitated from prior offenses.

The statute requires that the government put immigrants in mandatory detention “when [they are] released” from criminal custody. Congress imposed this requirement because, in its view, it needed to prevent people from entering society directly out of criminal custody and reoffending or fleeing before they could be deported.

The government then interpreted the statute to mean that it has the power to mandatorily detain an individual at any time after their release from criminal custody. But based on the plain words Congress wrote, it did not intend to impose mandatory detention on people, like Astrid, who committed a crime years or even decades ago and have long since rehabilitated themselves. It makes no sense to lock up people who don’t pose a flight risk or danger for years while their deportation cases make their way through a clogged system.

The result is that people who have never since reoffended, rebuilt their lives with their families, and become productive members of their communities are subject to mandatory imprisonment as their deportation case winds its way through the immigration court system, with no hearing to determine if they need to be locked up in the first place.

What’s at stake?

If we prevail, the government will be prohibited from detaining people who are not detained immediately when they are released from criminal custody, like Astrid, without a hearing. Instead, those individuals will be afforded an opportunity to go before a judge, who will decide if their imprisonment is necessary.

Can you challenge the mandatory detention law itself?

We have. The Supreme Court upheld mandatory detention before deportation in certain circumstances against a constitutional challenge by the ACLU in 2003. But the law remains an anomaly in our legal system. In every other civil detention system, outside of wartime or national security cases, due process requires a hearing before a judge to determine if the government is justified in taking someone’s freedom away.