The visit to Walter Reed National Military Medical Center marked Trump's first public appearance with a face covering since the virus began sweeping across the United States earlier this year.
Trump had previously refused to wear a mask in public or ask other Americans to do so, saying it was a personal choice, although he had said he would if he was in a crowd and could not maintain distance from others.
"I think when you are in a hospital, especially in that particular setting when you are talking to a lot of soldiers, people that in some cases just got off the operating table, I think it’s a great thing to wear a mask," Trump told reporters at the White House just before his visit to Walter Reed.
At the medical facility, Trump walked by media gathered for a carefully staged photo opportunity wearing a navy blue mask emblazoned with a presidential seal embossed in gold. He said only "thank you" as he passed.
Top public health officials have urged the use of masks to slow the spread of the virus, which by Friday had claimed nearly 134,000 American lives. Critics say Trump's refusal to wear one showed a lack of leadership.
Even as other officials in his administration called for the use of masks and social distancing, Trump, who faces re-election in November, pressured states to reopen closed economies.
But since many states relaxed coronavirus restrictions, the virus has found a new toehold. New US cases of COVID-19, the respiratory illness caused by the novel coronavirus, rose by more than 69,000 on Friday, a third straight daily record.
As of Friday, the number of confirmed US infections topped 3 million, according to a Reuters tally.A spokesman for Democratic presidential candidate Joe Biden said Trump had spent months ignoring the advice of medical experts and politicizing wearing a mask."Rather than taking responsibility and leading, he wasted four months that Americans have been making sacrifices by stoking divisions and actively discouraging people from taking a very basic step to protect each other," said the spokesman, Andrew Bates.