You're assuming that all landlords are rational. Many either see it as a leveraged investment where rent is just one factor to offset their cost, hoping that appreciation will make it profitable. Or the home had strong appreciation so that their cost relative to the current value is low. Or they have some sentimental attachment to the property and rather rent it out at a loss than sell it. In California especially, they might have locked in a low property tax rate which is a fraction of what you would pay when you buy the home today. For example, my in-laws pay $700/month in property tax. If I bought their house at market price today, my property tax bill would be $3,000/month.
For example I rent a home that's currently worth $1.3 million for $3,500/month. The landlord bought it in 2004 for $570,000. Would it make sense for the landlord to sell it instead of renting it out? Maybe, but based on their original investment they're getting a good return. If I were to buy that home off of them, my monthly payment would be more than double the rent. So this works for both of us I guess.