The attorney general’s office, which represents the government in legal matters, said the ruling was redundant since face masks are already mandatory in Brasilia.
“This interference from the courts is unnecessary,” a spokeswoman for the attorney general’s office told AFP.
However, it is a regulation the far-right president has repeatedly flouted, as Judge Renato Borelli pointed out in his ruling Monday.
“The president has a constitutional obligation to follow the laws in force in the country,” the judge wrote, ordering Bolsonaro to obey the regulation or face a 2,000-real ($365) fine.
The case was brought by a lawyer who said the president should be held to account for his “irresponsible behavior.”
Since the ruling, Bolsonaro has worn a mask at all public appearances.
Masks have been mandatory in public in Brasilia since April to curb the spread of the virus.
Bolsonaro regularly breaks the social distancing measures in place in the capital, giving handshakes and hugs at rallies, hosting barbecues, hitting the shooting range and going out for hotdogs, generally without a mask.
The president, who has famously compared the virus to a “little flu,” has railed against the measures state and local authorities are taking to fight it, arguing that business closures and stay-at-home measures are needlessly wrecking the economy.
Brazil has the second-highest COVID-19 death toll in the world, after the United States, at 55,000.
So far, Bolsonaro has never been fined for failing to wear a mask.
But his former education minister Abraham Weintraub was fined 2,000 reals last week for attending a pro-Bolsonaro rally in Brasilia without one.