A Theoretical Explanation of Activation Sparsity through Flat Minima and Adversarial Robustness