This isn't exactly true. Mortgages are just the cheapest leverage available, and terms and rates (30-year, low fixed rates) are much better in the US than elsewhere allowing people to leverage real estate 5-to-1 (or more with less than a 20% down payment).
You could leverage anything 5-to-1 and make a nice profit as long as it is an asset that keeps up with inflation; it doesn't even have to beat inflation for that bet to pay off.
But mortgages are a trap for most people because of the amortization and maintenance costs, not to mention the distorted market where renting is much cheaper than buying in every major city and most minor cities.
So a smart person would arbitrage the money saved by renting into the stock market and leverage up to the efficient frontier (2x leverage on 100% stocks or 3x leverage on something like 60/40 stocks and bonds).
They would end up significantly ahead of the person who only got ahead from a mortgage because of the much higher returns of stocks over time, as eventually the mortgage's leverage would decrease but the investor could keep constant leverage at rates below the average 30-year mortgage with margin loans.
"Houses are the only way to get ahead" is a lie told by the people who profit off real estate transactions, like real estate agents.