It's been shown to be a mostly rewarding strategy over the last century of so, averaged out at least, and so of course it's not really a foolish bet for most folks, but it's not the only way to secure one's financial health and isn't the ideal one for everybody.
Scrappy hustlers, skilled trade workers, and (SMB-scale) entrepreneurs in particular can often see a better return by investing in themselves and in ventures in their own community, where things are not so passive. Likewise, people with modest dreams and a preference for stability often might prefer securing a paid off house, car, etc before throwing too much money into the casino -- even on good bets. And others with strong and healthy family bonds benefit most by prioritizing enrichment and opportunity for family members who can be trusted to return the favor in less flush/capable times. etc
Many young people have only really been exposed to the idea of market investment as a retirement strategy, and its a good one for many, but there are a lot of roads to staying financially healthy through late life.