/ Updated 
By Pete Williams

A federal judge late Sunday blocked the Obama administration from taking any action that would force public schools to allow students the choice of bathrooms that match their gender identity.

The order came as many of the nation's schools prepare to begin the new academic year and means they might not face federal sanctions if they choose to do nothing different to accommodate the restroom and locker room choices of transgender students.

A sign protesting a North Carolina law restricting transgender bathroom access is seen in the bathroom stalls at a hotel in Durham, North Carolina on May 3, 2016.JONATHAN DRAKE / Reuters

Led by Texas, 13 states sued the federal government after the Education and Justice Departments sent a letter to schools nationwide in May, informing them that they must honor the bathroom choices of transgender students and could risk losing federal education funds if they do not.

Judge Reed O'Connor of Texas said the federal government failed to seek public comment first before issuing the letter. The Obama administration had argued that no such notice was necessary, because the letter was simply informing schools what courts and federal agencies had already determined.

Related: Transgender Bathroom Access to Extend to All Federal Buildings

But the judge said the letter was not merely advisory, because schools "jeopardize their federal educational funding by choosing not to comply."

The judge also said the federal law that bars public schools from discriminating on the basis of sex does not apply to transgender students. When the law was passed, "the plain meaning of the term sex," the judge wrote, "meant the biological and anatomical differences between male and female students as determined at their birth."

Related: Va. Court Tells School to Give Transgender Teen Bathroom Access

The federal government is almost certain to appeal, especially because the judge said his order applies nationwide. The Justice Department had argued that such an order would improperly impose one court's view on the many other courts wresting with the same issue "and on the many other states that have opted not to join this lawsuit, thereby preventing fuller development of the law on these important questions."

“The department is disappointed in the court’s decision, and we are reviewing our options,” said Dena Iverson, a Justice Department spokeswoman.

Related: Supreme Court Blocks Transgender Bathroom Ruling

Civil rights groups condemned the order.

Sarah Warbelow, legal director of the Human Rights Campaign, said it "puts thousands of transgender students at even greater risk of marginalization, harassment, and discrimination as they return to school this fall."

Earlier this month, the US Supreme Court put a hold another court order, in Virginia, that required a rural high school to allow a student who was born a girl but now identifies as male to use the boys' bathroom during the coming school year. The justices said the order should remain on hold while the Supreme Court considers whether to take up the transgender issue in its coming term.