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.