I think what you're really comparing is if the stock market or the housing market is a better investment, but you're not taking into account that the use of the property has value.
Think of it like a landlord, you're not just investing in a house to let it sit empty and then sell it later, you're buying it with the intention of collecting rent every month. Or to put it another way, it's like comparing the prices of dividend and non-dividend stocks without accounting for the dividend.
For a personal home, you need to account for the fact that owning it means you live there rent free. There's a monthly cost for the mortgage, but that cost doesn't increase with inflation the way rent does. Owning a home comes with expenses for upkeep and taxes, but once the mortgage is paid off those are the only thing you have to account for.