A federal judge has blocked an Obama administration directive that called on schools to safeguard the rights of transgender students, amid a lawsuit from the state of Texas.

The Obama administration has intervened on LGBT rights earlier this year after a string of laws attempted to roll back LGBT discrimination protections, purportedly to stop trans people from going to the bathroom.

The federal government wrote to every school in the US to advise them that they are obliged not to discriminate against trans people, issuing a directive in support of trans rights.

Republican officials in 13 states launched lawsuits against the directive – and this week, a federal judge in Texas has issued an injunction blocking the order.

Just days before pupils are set to return to schools, US District Judge Reed O’Connor blocked the directive in a preliminary injunction.

He ruled: “This case presents the difficult issue of balancing the protection of students’ rights and that of personal privacy when using school bathrooms, locker rooms, showers, and other intimate facilities, while ensuring that no student is unnecessarily marginalised while attending school.

“The resolution of this difficult policy issue is not, however, the subject of this Order. Instead, the Constitution assigns these policy choices to the appropriate elected and appointed officials, who must follow the proper legal procedure.”

The order states: “While this injunction remains in place, Defendants are enjoined from initiating, continuing, or concluding any investigation based on Defendants’ interpretation that the definition of sex includes gender identity in Title IX’s prohibition against discrimination on the basis of sex.

“This preliminary injunction will remain in effect until the Court rules on the merits of this claim, or until further direction from the Fifth Circuit Court of Appeals.”

HRC Legal Director Sarah Warbelow said: “Judge O’Connor’s decision to bar the Department of Justice from enforcing this important guidance puts thousands of transgender students at even greater risk of marginalization, harassment, and discrimination as they return to school this fall.

“All students, regardless of their gender identity, deserve to be able to learn in an environment free from discrimination. Despite this judge’s decision, schools are not barred from following the federal guidance, and school administrators still have a responsibility to ensure that the civil rights of all students are respected and that transgender students have access to facilities consistent with their gender identity. As lawsuits on the scope of Title IX proceed, we believe that justice will prevail as courts continue to recognise that discrimination against transgender students is a form of sex discrimination.”

The legal battle is expected to make its way to higher courts.