Your math example is silly on two counts. (1) you simply assume the rent and mortgage cost exactly the same, when they generally don't. (2) you ignore the downpayment. A renter doesn't have to make a huge downpayment, so if s/he has the money to make one, that is valuable flexibility - one can easily use that money in an emergency and can profit by investing that money in the meantime.
There are a lot of factors that can change the calculus. Buying is not always for everyone. People who move a lot where fees can eat up any benefits. Or people who do not have down payments or other cash flow problems (which can be a pretty effective market moat).
Rent, though, is often pretty comparable to a mortgage + taxes. In my area rent is substantially more for the same house.
So, liquidity is an important factor, no doubt about it. But I think one would be hard pressed to make a consistent investment profit that would make up for your 100% loss in rent compared to purchasing all other things being equal.