The ruling, made public Tuesday, declared that Bolsonaro was not exempt from the laws of the federal district, including Brazil's capital, and would face a fine of approximately $390 a day for failing to comply.
"The president of the republic must take all necessary measures to avoid the transmission of COVID-19 be that in order to protect his own health or that of those around him," Judge Renato Coelho Borelli wrote.
Bolsonaro has repeatedly been seen in public without a mask or face covering and has been seen wearing a mask improperly, including hanging it off of his ear.
"A straightforward Google search is enough to find numerous images of the defendant Jair Messias Bolsonaro moving around Brasilia and the surrounding federal district without using a mask and exposing others to the spread of this infirmity that has caused a nationwide upheaval," Borelli wrote.
Brazil has reported 1.1 million positive COVID-19 cases and a death toll of 51,271 related to the virus, according to figures by Johns Hopkins University.
Bolsonaro has sought to diminish the threat of the coronavirus publicly, referring to it as a "little flu" and clashing with local legislators by pushing them to keep businesses open.