Workplaces generally implement ridiculous dress codes to control people, rather than for practical reasons. It’s the same tactic often used by cults: control the little things, often related to someone’s means of expressing individuality, and they’ll eventually give in when you start to take control over more serious things.
It would be understandable if a factory had a rule against long facial hair so that it wouldn’t be caught in machinery, for example. But many offices require male employees to be clean shaven even when they will never be seen by clients at all, i.e. call center jobs where business is exclusively conducted over the phone.
The rules are even more extreme for female employees, who may be looked down on or even disciplined for things like not wearing makeup, or wearing comfortable shoes instead of heels. Many workplace dresscode/grooming rules are also racist and punish Black employees for having natural hairstyles. It’s all about control and maintaining power imbalances.