- An investment into the future (guaranteed housing, assuming they can pay the bills)
- An investment for their children (safe neighborhoods, good schools, etc)
- An investment into the community (homeowners tend to stay in their house for much longer, and are more interested in participating in community politics as a result)
You seem to be fixated on houses as a financial investment. They aren’t a great investment, you’re right. But you also can’t keep yourself warm and children sheltered with a million dollars in stocks.
There is a sub-branch of real estate investment, however, that has come to be known as "house hacking" where you explicitly DO treat your primary residence as an investment. Typically this includes buying a home larger than you need and renting out the extra space to roommates. Or buying a duplex and renting the other half. Purchased right, these can cover the cost of the mortgage, meaning you're sort-of living in your own home rent-free.
Another thing people do is move into a run-down house bought at a discount, live in it for two or three years, fix it up the whole time, sell it at a profit, and then move onto the next one.
Neither of these are usually palatable to those with families, but they are pretty popular as a way to get into real estate investing for those that are young, motivated, and have otherwise stable jobs.