President Donald Trump waves as he leaves the Rose Garden of the White House in Washington, Wednesday, July 26, 2017, after speaking during an event with the American Legion Boys Nation and the American Legion Auxiliary Girls Nation. Associated Press/Alex Brandon President Donald Trump's sudden announcement Wednesday morning that transgender people would be barred from serving in the US military may have been part of a last-ditch effort to save a House bill that partly funds a border wall, according to a Politico report.

House Republicans were reportedly at loggerheads all week over a spending bill and couldn't agree on whether to insist on a ban on Pentagon-funded gender reassignment surgeries.

The standoff threatened to tank the entire bill, which included funding for the border wall for which Trump campaigned and has been pressing, Politico reported.

While moderate Republicans believed that a ban on funding such operations would discriminate against transgender service members, some hardline conservatives had vehemently opposed the funding, arguing that it wastes taxpayer money.

"There are several members of the conference who feel this really needs to be addressed," Rep. Robert Aderholt, a senior House Appropriations Committee member and Alabama Republican, told Politico. "This isn't about the transgender issue; it's about the taxpayer dollars going to pay for the surgery out of the defense budget."

The Republicans who wanted a ban on funding the surgeries took the debate first to Defense Secretary James Mattis, who reportedly refused to budge on the issue before the Pentagon studies it further. Next, they turned to Trump, who blindsided lawmakers, the public, and reportedly even military leaders on Wednesday by tweeting out that transgender individuals would be barred from serving in the military "in any capacity."

Trump's move went far beyond the House Republicans' initial request, which was merely to block funding for gender reassignment surgery.

"This is like someone told the White House to light a candle on the table and the WH set the whole table on fire," one senior House Republican aide told Politico. The aide added that the Republicans had not expected Trump to take such sweeping action.

However, another House GOP aide told Business Insider that since the bill contains essential national security funding worth nearly $800 billion, the ban on Pentagon-funded sex reassignment surgeries would not have tanked it in the first place.

The federal government's plans for transgender service members and recruits have already been up in the air for some time. In June, Mattis delayed an Obama administration plan to begin allowing openly transgender recruits into the military by six months.

And House Republicans had already sparred over the issue several weeks ago when Rep. Vicki Hartzler first proposed the amendment banning funding for medical treatment for transgender service members. To the surprise of many GOP lawmakers, 24 moderate Republicans joined 190 Democrats in voting down the amendment.