The House delivered a rebuke to President Donald Trump on Thursday by voting to condemn his administration's move to restrict transgender men and women from military service.

A non-binding resolution opposing Trump's transgender ban passed 238-185. Every Democrat supported the resolution, while nearly every Republican voted against it. Five Republicans broke ranks and voted in favor: Brian Fitzpatrick of Pennsylvania, Trey Hollingsworth of Indiana, Will Hurd of Texas, John Katko of New York and Tom Reed of New York.

The Trump administration's policy bars people who have undergone gender transition from enlisting. It also requires military personnel to serve as their biological gender unless they began a gender transition under less restrictive Obama administration rules. The policy is being challenged in court.

Rep. Joe Kennedy, D-Mass., the resolution's sponsor, said Trump's policy amounts to "targeted discrimination." He said the House was voting to tell transgender people "that they cannot be banned from military service because of who they are."

The top Republican on the House Armed Services Committee, Rep. Mac Thornberry of Texas, opposed the resolution and said the vote attempted to politicize U.S. service members. Thornberry said because the resolution does not change law or policy it was a "messaging bill" that detracted from "serious issues that need to be discussed."

Ahead of the vote many Democratic lawmakers placed transgender pride flags outside their offices on Capitol Hill, including House Speaker Nancy Pelosi, who spoke from the floor in support of the resolution.

"There is no moral justification for this ban which violates every value of our American democracy," Pelosi said Thursday.

Under the Obama administration, the Pentagon announced that transgender people already serving in the military would be allowed to serve openly. Trump reversed that policy beginning in 2017 with a tweet that the government would not allow "Transgender individuals to serve in any capacity in the U.S. Military."

An estimated 14,700 troops on active duty and in the Reserves identify as transgender, but not all seek treatment. Since July 2016, more than 1,500 service members were diagnosed with gender dysphoria; as of Feb. 1, there were 1,071 currently serving. The Pentagon says it has spent about $8 million on transgender care since 2016. The military's annual health care budget tops $50 billion.

All four service chiefs told Congress last year that they had seen no discipline, morale or unit readiness problems with transgender troops serving openly in the military. But they also acknowledged that some commanders were spending a lot of time with transgender individuals who were working through medical requirements and other transition issues.

Speaking from the House floor ahead of the vote, Armed Services Chair Adam Smith, D-Wash., said the Trump administration policy is "primarily based on ignorance and bias against the transgender community."

"We have the best military in the world," Smith said. "We need highly qualified people to serve and to single out a particular group — to discriminate against them and to say they cannot serve — is bad for national security."