I believe that the face masks are worn to protect you from them, not as is often assumed vice versa
There are at least 3 reasons to wear masks in Japan:
When the wearer has a cold, to protect others.
At this time of year, to protect hay fever sufferers from from pollen: the masks are N95 filters. Hay fever is endemic, thanks to planting exactly the wrong kind of cedar all over Japan after WW2.
Among some younger people, a strange fashion trend to further isolate them from society. Although there's also the current huge-spectacle-frame-without-lenses fashion, which somewhat negates the isolationist aspects.