He has previously said that he would not wear a mask and mocked Democratic rival Joe Biden for donning a face mask at a previous event.
On a visit to a Ford plant in Michigan last week, Trump wore a mask for part of the trip, but took it off in front of the cameras.
Michigan Attorney General Dana Nessel accused the president of acting like a “petulant child” for flouting the measure.
“I had one on in an area where they preferred it, so I put it on and it was very nice. But they said, ‘Not necessary here,'” Trump told reporters.
The president was visiting the Walter Reed military hospital outside Washington, where he met wounded soldiers and health care workers.
Trump: I’ve never been against masks pic.twitter.com/FVp4HRWZdy
— Acyn Torabi (@Acyn) July 11, 2020
The change of tone came as the US recorded 66,528 coronavirus cases on Saturday, a new daily record.
Speaking to Fox Business Network last week, Mr Trump said: “I’m all for masks.”
He added that he sort of liked how he looked with one on, likening himself to the Lone Ranger, a fictional masked hero who with his Native American friend, Tonto, fought outlaws in the American Old West.
But when the US Centers for Disease Control (CDC) in April began recommending people wear masks or cloth coverings in public to help stop the spread of the virus, Mr Trump told reporters he would not follow the practice.
“I don’t think I’m going to be doing it. Wearing a face mask as I greet presidents, prime ministers, dictators, kings, queens – I just don’t see it.”
Some media reports have suggested aides have repeatedly asked the president to wear one in public.
In an interview with the Wall Street Journal last month, Mr Trump suggested some people might wear masks to signal disapproval of him.
He also said he took issue with people touching their faces after taking their mask off.
“They put their finger on the mask, and they take them off, and then they start touching their eyes and touching their nose and their mouth. And then they don’t know how they caught it?” he said.
The US has seen another 66,528 infections in the past 24 hours, a record for one day, and a total of almost 135,000 deaths since the pandemic began, according to Johns Hopkins University data.
Louisiana has become the latest state to order that masks be worn in public.
Starting today, Democratic Governor John Bel Edwards has ordered the closure of bars across Louisiana and tightened restrictions on restaurants, which will no longer be able to serve customers inside.
“If you don’t like the mask mandate, then don’t like it while you wear your mask. If you want to be mad at me about it, then be mad at me about it,” Governor Edwards said.
Neighbouring Texas has recorded another rise of coronavirus infections, with a record 10,500 new cases recorded on Saturday.
The governor of South Carolina has issued an order banning sales of alcohol after 23:00 in bars and restaurants to try to stop the spread of the virus.