Trump said he'd let his military leaders decide and gave the job to Mattis to find out what his military leaders recommended. They made the decision. He has their back and Trump is making their decision law.
".....James Mattis, the defence secretary who is on holiday, was understood to have learnt about the decision after the president tweeted it......."
".....The Pentagon appeared to be caught off guard by Trump’s announcement, and deferred to the White House when reached for comment. "We will continue to work closely with the White House to address the new guidance provided by the commander-in-chief on trans individuals serving the military,” a spokesperson for the defense department said. “We will provide revised guidance to the department in the near future.”......
........An administration official fueled speculation over the president’s motives
by suggesting that the shift was a political ploy that would force Democrats facing re-election in states won by Trump into complex culture wars.......