Unaccompanied and undocumented immigrant children have the right to a court hearing to determine whether they can be released, a federal appeals court ruled Wednesday.

The three-judge panel on the Ninth Circuit Court of Appeals disagreed with the government’s argument that laws passed after the 1997 Flores v Reno Supreme Court case replaced the bond hearing requirement by giving a federal agency authority over unaccompanied minors. That agency is the Office of Refugee Resettlement, which is part of the Department of Health and Human Services.

“In the absence of such hearings, these children are held in bureaucratic limbo, left to rely upon the agency’s alleged benevolence and opaque decision making,” Judge Stephen Reinhardt wrote for the court, later adding: “Not a single word in either statute indicates that Congress intended to supersede, terminate, or take away any right enjoyed by unaccompanied minors at the time of the acts’ passage. Thus, we hold that the statutes have not terminated the Flores Settlement’s bond-hearing requirement for unaccompanied minors.”

The United States saw a surge of unaccompanied minors at the southern border in 2014, though the number of apprehensions at the border have since dropped. Immigrants rights advocates see the ruling as a victory for undocumented children, but the ruling could also  place a greater burden on the nation’s immigration court system, which is overseen by the Justice Department. Those courts have more than half a million cases pending, according to a March report by the Executive Office for Immigration Review.

The opinion highlighted some examples of detainment. Hector, who was referred to only by his first name, was detained in California at 15 years old and held by the ORR for 489 days, despite repeated attempts from his mother to have him released into her custody. In his declaration, Hector described the conditions of the facility, saying the guards “lock us up in the cells every night, to sleep on benches made out of cement with mattresses.” During 16 months, Hector was not provided with a lawyer or an explanation “for his continued secured detention,” the Ninth Circuit said. “I feel desperate,” he wrote. “My only wish is to leave detention, live with my mom, and study.” He was later released into the custody of his mother.

Politico reports that “government lawyers argued that meetings HHS officials hold with detained minors are sufficient to protect their interests.” But that argument didn’t appear to convince the panel. The decision notes: “The hearing is a forum in which a child has the right to be represented by counsel, and to have the merits of his or her detention assessed by an independent immigration judge.”

“The issue with children in detention has been that the government knows best and we should leave it to them to decide. It’s a real dangerous proposition and here they flatly rejected that,” Holly Cooper, a lawyer representing the class of plaintiffs and the co-director of the law clinic at the University of California, Davis. “In our country, one of the foundational concepts we have is one of checks and balances and when it comes to liberty, those checks and balances are imperative for the individual's freedom.”

Immigrant advocates are also happy with the outcome. “We are celebrating this decision because it gives a neutral forum to challenge overzealous enforcement and, most importantly, allows us to advocate for the best interests of the children,” Lenni Benson, a professor at New York Law School, told The New York Times. The Justice Department, meanwhile, is reportedly considering next steps, which include “asking a larger set of 9th Circuit judges to take the case or seeking review by the Supreme Court.”