This question is based on a faulty premise, at least for the British Army. Soldiers were not required to be clean-shaven to wear gas masks; the regulations that regulated facial hair for British soldiers dated from a time before chemical warfare was a fact of life. Soldiers in the field also tended to ignore the regulations, as shaving in the field was tricky thanks to limited supplies of hot water.
In the years before WWI, British soldiers were forbidden to wear beards. Instead, they were, in effect, required to wear moustaches. Regulations forbade the shaving of the upper lip, though the chin, bottom lips and cheeks had to be free from hair. Meanwhile, civilian fashion was for the face to be completely clean-shaven. Men might risk an upbraiding for shaving before going on leave. During the war, the regulation was relaxed. Reservists and volunteers tended to ignore it, and stay clean-shaven. In 1916, an officer was court-martialled for persistently shaving his upper lip. He was an actor in civilian life, and argued that, should he grow a moustache, he risked jeopardising his ability to find work following the war - he worried that shaving the moustache off would give him a rash that would make things difficult for him. While he was successfully prosecuted, he was saved by the adjutant general at GHQ, Lieutenant General Sir Nevil Macready. Macready, who disliked his own moustache, quashed the sentence, and changed the regulation to allow the upper lip to be shaved. From then on, most men in the British Army would be clean-shaven.
However, this did not necessarily apply in the trenches. Shaving was rarely practical, thanks to the poor conditions. Hot water was rare, and was seen as being more useful for washing than for shaving. While some men did try to shave, using whatever hot water they could scrounge (or even tea), most grew scruffy beards. Once they came out of the line, though, bearded men tended to shave. Shaving off these beards was seen as an essential way to cleanse the dirt of the trenches.