This is about your immune system not muscle. The gym is a playground for germs and viruses.
More muscle mass means a better immune system. When you build muscle you also lose fat. Less fat means your body works better. More efficient systems means better immune health.