Unless you are looking at REITs, investing in real estate as an individual necessarily means you'll be investing in only a small subset of all the real estate markets in the country. There is still a lot of internal migration within the USA -- it gives us a big advantage at adapting and recovering from economic changes and depressions/recessions especially compared to places like the EU -- so markets where people want to live and where jobs are plentiful are likely to keep expanding so real estate in those markets will continue to be, on average, a good investment.
Markets where internal migration has already been shrinking populations for quite some time now can give a sense of what a real estate market with a shrinking local population looks like.
-Property values decline a LOT (single family homes selling for five figures rather than six or seven figures).
-Rents don't decline as much. Numerous posters living in the rust belt have talked about finding properties that don't just satisfy the 1% rule but the 2% rule (annual rent of at least 24% of the purchase price).
-So you can survive as a landlord in a declining market, but if you're leveraged up on mortgages betting on price appreciation rather than price decline before your market transitions from growth to decline it could end up a disaster.
The challenge is figuring out which real estate markets in the future will look like DC, Denver, or Bozeman (big, medium, and small markets that are currently growing) and which real estate markets in the future will look like Detroit, Syracuse, or Hamburg, IA.
Changes in the birth rate or immigration may slightly shift how common those two kinds of markets are.