If you sell your house 2 years after buying it, unless the prices really skyrocketted during that time you should have rented instead.
If you stay 30 years in your house however it's financially much better to buy rather than renting.
Of course there are non-financial aspects (freedom of modification for homeowner, easier to move out for renters) but the financial equation boils down to how long you stay in the same house. Exactly where is the cut-off depends where and when you live.
If your wages keep up with inflation (say 3% for example), in 10 years you'll be making about 35% more dollars but your housing payment stays the same. If your home value tracks inflation, it will also be up 35% after a decade, but your payment stays the same. And if you're lucky, there may have also been appreciation above inflation. Inflation melts your fixed rate debt and grows the nominal value of your asset, speeding the rate at which you build wealth in the form of home equity.
Over that same period, a renter is certain to have experienced significant increases in their housing costs. They may have saved and invested more than the homeowner over the first few years of homeownership, but as you know this is a long-term game.
I guess it comes down to what form of risk/investing you are most comfortable with and whether you value the intangible lifestyle things like getting to customize things to your liking. Getting to purchase an asset with between 5-33x leverage in the form of low fixed rate debt seems like a pretty unique opportunity for most people who would not be comfortable borrowing for other forms of investment.
Sure, you can make the argument that I can hopefully expect some capital gains down the road if/when I sell the place. But that's not guaranteed (consider all the people underwater on their mortgages, for example, after the 2008 financial crisis; I wouldn't be at all surprised if something like that happens again during my lifetime), and it may well be that putting that money in the stock market would net me better returns over time.
But it really just depends on your local housing market. In some places it makes more financial sense to rent (rent < interest+taxes+upkeep), and in some places to buy (rent > interest+taxes+upkeep). And sometimes the financials aren't the #1 driver of the decision, anyway.