The Supreme Court decided on Monday to hear a case appealed by the Trump administration regarding whether undocumented immigrants and longtime lawful residents who previously committed minor offenses can later be detained for possible deportation.

The California ruling in the case of Nielsen vs. Preap, decided by the U.S. 9th Circuit Court of Appeals in San Francisco, held that such immigrants who were previously jailed may not be later detained by immigrants agents, nor held indefinitely without a hearing, if they pose no public danger and are at low risk of fleeing, according to the Los Angeles Times.

The case’s main plaintiff, a Cambodian refugee named Mony Preap, became a lawful permanent resident in 1981 but was convicted on two counts of marijuana possession in 2006. Preap was then taken into custody in 2013 under the “mandatory detention” part of the law, which states that the Department of Homeland Security “shall take into custody any alien” convicted of a “deportable” offense “when the alien is released.”

The court decision, however, ruled that the phrase “when the alien is released” referred only to the immediate moment a non-citizen such as Preap was released from jail, and not later. Therefore, previously released non-citizens are not subject to mandatory detention for past offenses.

“We therefore hold that the mandatory detention provision…applies only to those criminal aliens who are detained promptly after their release from criminal custody, not to those detained long after,” Judge Jacqueline Nguyen wrote.

The decision also stated that more than 30,000 non-citizens are held in “prison-like conditions” daily; that the mandatory detention rule covers those with a “broad range of crimes,” such as simple drug possession; and that the rule applies to longtime, lawful residents who have resided in the U.S. for decades. After the decision, Preap was released from custody.

“Instead of focusing mandatory detention on high-risk individuals who are coming out of criminal custody, the government’s expansive interpretation would sweep up individuals who have been living peaceably in the community for more than a decade and pose neither a danger nor a flight risk,” American Civil Liberties Union lawyers told the Times.

The Trump administration appealed the ruling on the argument that the law requires “mandatory detention” for all non-citizens who may be deportable because of criminal records. The administration also argued that the ruling would allow for a “gap in custody” and would “frustrate the [government’s] ability to remove deportable criminal aliens from the United States.”

The case is similar to a previous decision the Supreme Court made last month in the case of Jennings vs. Rodriguez, in which the court held that federal law did not give non-citizens rights to a bail hearing after six months in custody—meaning that such immigrants in custody could be held indefinitely. The Supreme Court sent that case back to the 9th Circuit, however, to decide if infinite detention without a hearing violated the Constitution.

SCOTUS is scheduled to hear Neilsen vs. Preap in the fall.