Dunford was not aware that Trump was going to announce the ban, a U.S. official said. The official was not authorized to discuss the matter and so spoke on condition of anonymity.
Trump's announcement caught the Pentagon flat-footed and unable to explain what it called Trump's "guidance."
"Please be advised that the United States Government will not accept or allow Transgender individuals to serve in any capacity in the U.S. Military," the commander in chief tweeted.
Trump wrote that he had consulted with "my generals and military experts," but he did not mention Mattis, the retired Marine general who recently told the service chiefs to spend another six months weighing the costs and benefits of allowing transgender individuals to enlist. At the time, Mattis said this "does not presuppose the outcome of the review," but Trump's tweets appeared to have done just that.
The Pentagon has not released data on the number of transgender people currently serving. A Rand Corp. study has estimated the number at between 1,320 and 6,630 out of 1.3 million active-duty troops.
Criticism for Trump's action was immediate and strong from both political parties.
John McCain, the Arizona Republican and Vietnam War hero, said Trump was simply wrong.
"Any American who meets current medical and readiness standards should be allowed to continue serving," he said. "There is no reason to force service members who are able to fight, train and deploy to leave the military -- regardless of their gender identity."
Not everyone at the Capitol agreed.
Rep. Duncan Hunter, a California member of the House Armed Services Committee, said: "It's about time that a decision is made to restore the warrior culture and allow the U.S. military to get back to business."
Transgender people already in uniform were concerned about what comes next.
"Everybody is hurt, everybody is scared," said Rudy Akbarian, 26, who is in the military but did not want to identify his branch.
Trump's sudden declaration appears to halt a decades-long trend toward more inclusive policies on military service, including the repeal in 2010 of a ban on gays serving openly. President Bill Clinton in 1993 began the push to allow gays to serve. In December 2015, President Barack Obama's Pentagon chief, Ash Carter, announced that all military positions would be open to women. Liberalizing policy on transgender troops was the next step.
Just last week, when asked about the transgender issue at a Senate hearing, Gen. Paul Selva, vice chairman of the Joint Chiefs of Staff, said, "I am an advocate of every qualified person who can meet the physical standards to serve in our uniformed services to be able to do so."
Transgender service members have been able to serve openly since 2016, when Carter ended the ban. Since Oct. 1, transgender troops could receive medical care and start changing their gender identifications in the Pentagon's personnel system.
Carter also gave the services until July 1 to develop policies to allow people already identifying as transgender to join the military if they meet normal standards and have been stable in their identified genders for 18 months.
On June 30, Mattis extended the July 1 deadline to next Jan. 1, saying the services should study the impact on the "readiness and lethality of our forces."
White House press secretary Sarah Huckabee Sanders said Trump had made "a military decision." She said it was his judgment that allowing transgender service "erodes military readiness and unit cohesion."
Sanders said the "president's national security team was part of this consultation" and that Trump "informed" Mattis of his decision immediately after he made it on Tuesday.