We aren't certain that it's masks. But they did little else (e.g. no lockdowns or travel restrictions); so it's either masks, or something unknown. Occam's Razor says masks are more likely.
There are other anecdotal cases about mask efficiency. E.g. there is a hair salon in US where two hairdressers got COVID, and they served 139 clients in 8 days, before testing positive; one was symptomatic for the entire period, the other one for 5 days. Per company policy, they wore mask consistently while working with clients.
During that time period, they infected 4 people - but all of these were their family or roommates. None of the clients they serviced developed symptoms then or within a month, and of the half who consented to testing, none tested positive.
Besides, we do have good reasons to believe that masks are efficient just based on physics and biology alone. We do know that masks are definitely effective at stopping saliva droplets, and we do know that droplets definitely spread COVID. So even if it has other vectors (e.g. aerosols), masks would still reduce the overall viral load, and thus chances of infection.
I could not find a reliable source that ascribes Japan's relative success to masks. Some ideas are discussed in https://www.bbc.com/news/world-asia-53188847 . The advice from Japan's ministry of health on masks is not a ringing endorsement, either: https://www.mhlw.go.jp/stf/seisakunitsuite/bunya/kenkou_iryo... .