A cash-flow negative house that doesn't appreciate and become ever more cash-flow negative is a TERRIBLE investment compared to the S&P 500.
In the simplest terms, take a $100k house. 20% down = $20k downpayment + $3k closing costs. Generally, this is a house that would rent for at least $800/m.
Your payment is $337/m. Of that, only $143 is principal. If the house is even 5% cash-flow negative - that means you're only getting ~$100/m in principal.
You'd get ~$145 on your $23k downpayment in the S&P 500. And instead of being cash-flow negative and taking money OUT of your investments, you could instead ADD to it.
Add to that the fact that you'll pay an additional ~6%+ transaction costs at closing -> And even a 5% cash-flow negative house with 0% appreciation is likely to come out negative.
This only works because the Fed pretty much guarantees that house prices will appreciate >3% per year for the last 20 years.
3%*5:1 leverage => Crushes the S&P 500 average. Even if you're 10% cash-flow negative, it usually beats the S&P.
Add to that the fact that $250k of the capital gains are tax free -> And that pretty much eliminates the 10% transaction fee and makes it better tax-wise than the S&P 500.