It’s not that simple. First, risk is a also factor. But a real estate investor is not just looking for capital gains. They are looking at rent yields against costs (taxes, insurance, maintenance, interest).
Real estate can be a good investment even without appreciation in real terms. And that is a good thing.
Real estate investors play an important role in society. Without landlords, it would be impossible to rent a home. So anyone without the ability to purchase a home would have to rely on friends and family or charity, or sleep in the street.