President Donald Trump's abrupt decision to block transgender people from serving in the U.S. military came after a GOP fight over gender reassignment surgery threatened funding for the president's border wall, Politico reported Wednesday.

House Republicans are pushing to pass a defense spending bill that includes funding for Trump's proposed barrier on the U.S. border with Mexico. Some GOP members of Congress were worried that bill could get hung up on demands from some members to ban government funding of gender reassignment surgery, according to Politico.

After some House Republicans appealed to Trump, he took the request a step further, tweeting that his administration will not "accept or allow" transgender people to serve in the military "in any capacity."

Trump's tweets appeared to catch congressional leaders off guard. Following Trump's announcement, Senate Armed Services Committee Chairman Sen. John McCain, R-Ariz., criticized it as "yet another example of why major policy announcements should not be made via Twitter."

The White House did not immediately respond to CNBC's request to comment on the Politico report.

Read the full Politico report here.