“This is just another building block on the large and growing number of courts to hold that discrimination against transgender people is illegal,” she said.

Kenosha Unified School District had argued that the federal law does not apply to transgender people as a group and that the harm to other students by Mr. Whitaker’s using the boys’ bathroom, particularly to male students, outweighs any harm to him. It also urged the appeals court to reconsider whether the case should be thrown out. Ronald Stadler, a lawyer for the school district, did not immediately return a message.

Judge Ann Claire Williams of United States Circuit Court declined to reconsider and rejected the district’s other arguments, saying harms to others are speculative while harms to Mr. Whitaker are well-documented. Those include suicidal thoughts as well as medical issues stemming from avoiding the bathroom.

According to the lawsuit, when Mr. Whitaker first asked to use the boys’ bathroom, the school said he could either use a gender-neutral bathroom in the school’s main office or the girls’ bathroom. He used the boys’ bathroom anyway without issue for six months, it says, until a teacher saw him washing his hands there and reported it to school administration.

Ms. Turner, who works with the Transgender Law Center, said Mr. Whitaker’s win could affect a case with the Seventh Circuit of the United States Court of Appeals — that of Gavin Grimm, a transgender high school senior in Virginia who sued his school board for the right to use the boys’ bathroom. The United States Supreme Court was set to hear his case but sent it back to the lower court after President Trump’s administration revoked guidance from former President Barack Obama directing public schools to allow transgender students to use bathrooms aligned with their gender identities.