They dont make new land anymore while population growth continues and more and more money is printed. The changing climate [real as well as political] also makes many places less livable than before. That all makes for strong appreciation at good places.
Land and real estate are very legitimate investment vehicles. That fact is not diminished just because they can lose value. All investments can lose value.
Your 2-N homes are also investments, just riskier ones than they were thought to be previously. Whether people know this or are just blindly parroting outdated advice remains to be seen.
It is possible to use your primary residence as an investment, but everyone still needs a place to live, so it is also a form of consumption.
If you want to consider it an investment by definition, then you should actually explain how it is an investment.
Speculation is allocation of capital to an entity because you believe you or someone else will need it in the future. e.g. A banker buying a baker's oven.
A primary residence is at best an investment (you need to live somewhere to earn an income), a second residence is purely speculation.
The housing market is highly highly leverage with the median ratio ~= 14:1 [1]. Since small changes to the amount of money inflated by commercial banks and the Federal Reserve can have extreme consequences on prices, it's highly inadvisable to speculate in highly leverage markets.
[1] 7% median down payment, 1/.07~=14 https://www.attomdata.com/news/mortgage-and-finance/q3-2017-...
The average American loses money on real estate once you factor in inflation, property taxes, interest, and maintenance. Yes, we hear all sorts of stories about houses appreciating six figures per year in the Bay Area but that is very, very far from the typical American experience.