There are many things wrong with this policy. There is no dark magic that turns teenagers into criminals on their 18th birthday, even if they were born outside the United States. Given the damage that incarceration can do to young adults, every alternative should be pursued before turning teenage asylum seekers over to adult detention. And, as the Ramirez lawsuit indicates, the procedure itself may be illegal. Federal law requires ICE to place children and teenagers in the least restrictive setting possible, even after they turn 18.

Critics say the number of migrant children who face jail as they “age out” of youth shelters is climbing, and it’s easy to see why. The number of detained migrant children has already quintupled since last year, largely because children are being held in shelters longer. The average length of stay has increased from 34 days in 2015 to almost 60 days now, and many children are kept much longer. Yearlong stays are not uncommon, and cases of 500 days or more have been reported. As those numbers grow, the entire shelter system (some 100 facilities scattered across the country) is nearing capacity.

The best of those shelters may feel like havens to children who fled extreme poverty or violence, and faced incredible risks to make it across the border. The worst shelters are dens of abuse and neglect. At either end of the spectrum, the children themselves face tedium, a lack of freedom and profound uncertainty, especially when their 18th birthday approaches. “It’s a really anxiety-inducing period,” says one of Mr. Ramirez’s lawyers, Kate Melloy Goettel. “We try to prepare them for it, but it can be hard to grasp.”

Health and Human Services officials have said that the longer stays are an unfortunate but inevitable byproduct of improved safety precautions: It takes time to verify that prospective sponsors are who they claim to be, and to ensure that these already vulnerable and traumatized minors won’t be subjected to abuse once they leave the care of the Office of Refugee Resettlement. As proof of the necessity of their diligence, they point to a handful of children who were unwittingly placed with human traffickers in 2014.

That argument withers under scrutiny. Yes, the threat of trafficking is real, and protections are needed to guard against it. But it’s difficult to see how incarcerating teenagers for the crime of turning 18 protects them more than, say, releasing them to a willing sponsor who has cleared a basic but thorough background check. Stricter requirements have succeeded in scaring off prospective sponsors, many of whom are undocumented themselves or who have undocumented relatives. But their fear does not necessarily speak to their fitness as guardians.