A gender-neutral sign at a restaurant in Durham, N.C., where transgender advocates fought to repeal a law that barred them from bathrooms. (Sara D. Davis/Getty Images)

A federal appeals court has upheld a Pennsylvania high school’s policy of allowing transgender students to use bathrooms and locker rooms consistent with their gender identities, marking a victory for transgender students who say it is critical for their well-being.

The U.S. Court of Appeals for the Third Circuit ruled Thursday in favor of the Boyertown Area School District, which two years ago enacted the policy on restroom and locker room use. The three-judge panel ruled unanimously for the school system the same day oral arguments concluded, making their decision with unusual speed. The judges are expected to issue a full court opinion in the coming weeks.

The decision was a relief to transgender students and their advocates, who say that policies such as the one in Boyertown are important to their safety and for their transition. But critics, such as the students who sued the Boyertown Area School District, say the policies violate the privacy of students who are not transgender.

Transgender students have celebrated major court victories in the last couple of years, even as the Trump administration moves to curtail their rights. Shortly after she was confirmed as education secretary, Betsy DeVos and Attorney General Jeff Sessions rescinded Obama-era guidance that directed schools to accommodate transgender students in bathrooms and locker rooms according to their gender identities.

Tuesday, a federal judge ruled that a Virginia school board violated the rights of a transgender student, Gavin Grimm, when it barred him from the boys’ bathroom.

But groups and students opposed to such policies, such as the Alliance Defending Freedom, have challenged policies similar to the one in Boyertown in lawsuits across the country, including in a small town in Oregon and a Chicago suburb.

A half-dozen high school students sued the Boyertown Area School District last year after they encountered transgender classmates in bathrooms and locker rooms. They argued that allowing transgender classmates to change alongside them in locker rooms violated the privacy of students who are not transgender. One boy, identified as Joel Doe in court documents, said he learned of the policy only while undressing in the locker room and saw a transgender classmate doing the same.

“The [school] administration has a duty to all of its students to protect their privacy and their safety,” said Christiana Holcomb, an attorney with the conservative Alliance Defending Freedom who is representing the students. Holcomb said the school should accommodate transgender students in other ways, perhaps directing them to use other facilities. “What they cannot do is violate every student’s right to bodily privacy,” she said.

The American Civil Liberties Union, which intervened in the case to represent a transgender student and the school district, argued the policy is constitutional. And it went further, saying that removing transgender students’ right to use facilities aligned with their gender identities is unconstitutional sex discrimination.

“Not only is the school’s policy constitutional, but striking it down would affirmatively violate the rights of transgender students,” said Joshua Block, an ACLU attorney. “Traditionally, privacy claims have always been about being forced to undress or have your body exposed to others. That’s not happening to anyone under any circumstances.”