A house is something that fulfills your direct needs, unlike S&P500. You 'miss the opportunity' in exhcange for feeling safe about your future, which leads to more rational choices long term.
Or less rational like tying yourself to a place, missing opportunities in professional and personal life or opportunities to experience a different life.
Buying early in life is in my view almost always wrong.