It is not necessary to shake a mask before wearing it.
Shaking the masks or drying them under the sun before using them is a personal choice. These actions generally do not hinder the protective effect of the mask.
Medical staffers do not shake their masks because a mask is sterile when taken out of the package. Deliberately shaking and exposing it in the air can cause unintended contamination in places such as hospitals.