The gas mask is used to protect the protagonists from suffocating on any airborne gases. The gas mask is used prominently in the Jewel Store Job (if the smart approach is taken) to keep Michael and the gunmen from inhaling any of the knockout gas. Michael also uses it during the rappelling sequence of Three's Company, and as part of the Scuba Gear outfit during Monkey Business.
It is also utilized by Bugstars Pest Control.
There's a bulkier version of the mask introduced in GTA Online through the Heists Update. It is available to buy after The Fleeca Job Finale from Vespucci Movie Masks. Unfortunately, it does not protect the player from toxins such as Tear Gas, making it a "novelty" item, likely because it has no filter installed.
The full face gas mask is based on the real life MCU-2/P.