A panel of the US Court of Appeals for the District of Columbia Circuit in a 2-1 ruling said the 2025 policy was unlawfully motivated "by the bare desire to harm a politically unpopular group."
But the Pentagon has broad powers to set enlistment standards, the court said, and can continue to ban transgender people from newly entering the military pending the outcome of a lawsuit by transgender current and would-be service members.
"It appears to us to be a much greater hardship to end a military career than to delay the start of one," wrote Circuit Judge Robert Wilkins, an appointee of Democratic President Barack Obama.
Circuit Judge Justin Walker, a Trump appointee, in a dissenting opinion said courts "have neither the expertise nor the authority to decide whether the military can exclude the plaintiffs from its ranks."
Jennifer Levi of LGBTQ rights group GLAD Law, who represents the plaintiffs, applauded the decision.
"This decisive ruling confirms that the Trump Administration has no legitimate basis to discharge transgender service members who have met every demanding standard and proven, time and again, their fitness and dedication to serve," Levi said in a statement.
Defence Secretary Pete Hegseth indicated the government would appeal the decision to the Supreme Court.
"See you at SCOTUS," Hegseth wrote on X in response to a Fox News reporter's post about the decision.
The ruling partially upholds a 2025 decision by a Washington, D.C.-based federal judge who had blocked the entire policy from being implemented pending further litigation. The judge said the policy amounted to sex discrimination and likely violated the US Constitution's guarantee of equal protection under the law.
Trump in a January 2025 executive order said that adopting a transgender identity "conflicts with a soldier's commitment to an honourable, truthful, and disciplined lifestyle."
Hegseth implemented Trump's order soon after, prompting legal challenges.
The ban on military service is part of a broader effort by the Trump administration to eradicate the recognition and accommodation of transgender people throughout American life.
Federal agencies have dropped lawsuits filed on behalf of transgender workers, ended settlements that benefited transgender students and launched investigations into hospitals and doctors for providing gender-affirming treatment to minors.
The military has about 1.3 million active-duty personnel, according to Department of Defence data. While transgender rights advocates say there are as many as 15,000 transgender service members, officials say the number is in the low thousands.