Question: Would not wearing a mask in public spaces (when the law demands doing so) result in a Chillul HaShem?
Answer: Yes, if a religious person would not abide by the law which would result in people speaking badly about Jews, it would be included in the prohibition of Chilul Hashem. However, in a place where the law is not adhered to even by the non Jewish residents, it wouldn’t be Chilul Hashem.
What defines a Chillul HaShem?
Colloquially, the term Chilul Hashem is used when referring to a behavior that denigrates Torah observant Jews in the eyes of the general population. However, the actual mitzvah of Chilul Hashem as understood in halacha refers to an action that demonstrates one’s lack of commitment to Hashem in the eyes of the observant. Thus, the main component of this Mitzvah is not to transgress the commandment to sanctify Hashem’s name by giving up one’s life in a time of a decree against the observance of Torah and Mitzvos or when posed with the ultimatum of either giving up one’s life or doing one of the three big prohibitions, idle worship, incest and murder.
Additionally, one who violates any prohibition out of spite would be violating the prohibition of Chilul Hashem as well.
Nonetheless, it has been accepted colloquially to include in the term Chilul Hashem the concept that one should not do anything which would cause people to speak badly about Hashem and those who are loyal to him. The more religious and pious a person is the more they should be careful in their actions not to cause a Chilul Hashem, even by doing something which is completely legal but the onlookers would view it differently.