1.) Prices change over time. Someone who paid $2.4M for a 13-unit apartment block (as our landlord did) collects over $400K/year in rent at $2600/unit/month. That's a 17% return, well above interest, taxes, and property management. That same building might sell for $10M now, which would be a 4% return, barely enough to cover interest, let alone taxes and management. Indeed, new luxury apartment blocks are often renting for $7600/month+ (and they tend to get filled by Googlers on corporate business or new to the area - see point 2).
2.) Different people want different things, and so the pool of buyers and renters are often completely disjoint, with different means. I was shocked to discover that the whole 13-unit complex I'm in sold for just $2.4M (granted, 2012, when prices weren't as insane; see point #1). That's less than some of my friends are paying for single-family homes. And you're right, it's not exactly equivalent: it's multi-family, so there are neighbors, and no real yard (but it does have a common-space lawn). But would I pay triple the housing costs to not have neighbors? No - they don't annoy me that much.
The thing is, by being willing to live in multi-family housing, you change the population of people who are competing with you for housing. Most of the neighbors here are Mexican immigrants, blue-collar workers, or tech-workers who are doing the same thing we're doing (sacrificing some standard of living to save money). We aren't competing with other folks who have Google or Apple stock options, we're competing with folks who are making minimum wage and packing 3-4 families into a unit to make ends meet. In other words, you can save a lot of money by not caring about status and appearance.
(Actually, after Zillowing nearby prices, it makes me wonder if we should just buy a small duplex or multi-family apartment block, live in one unit, and rent out the other ones. Rent often nearly covers the full mortgage, and with a large down payment, it starts getting profitable quickly. There's still the issue of the housing stock in California being pretty terrible, though.)
As long as appreciation + inflation over the period you stay in a house you buy is greater than your interest rate, buying a house is effectively free (minus the downpayment). People bring up maintenance, however this is already taken into account with rental price increases, vs. a fixed 30 year mortgage. Maintenance is an overplayed expense, honestly.
EDIT:
I can't reply to the children comments, but I just want to say that the situation mention is absurd.
1. 2.7M worth of 1985 S.F. property would be entire neighborhoods and give you more than 6%. Forget houses, 2.7M in 1985 would buy you acres of prime real estate.
2. Even if it did not, it's not necessary to put down 20% on a house.
3. Investing and purchasing a house are not mutually exclusive strategies.
4. Overall, over 40 years buying will always be better.
Buy scenario, free maintenance and no property taxes: Living in a $2.7M house means a downpayment of $540,000 plus $6.6k/month of mortgage (assuming 2% interest rate on ~$2.2M mortgage paid over 40 years). Your housing prices increase 6%/year on average (1985 - 2015 average, http://www.doctorhousingbubble.com/california-housing-histor...). You sell 40 years later your house for $22,628,579.
Rent scenario: You put your $540,000 plus $4400 per month into your average stock market. 1985 to 2015 the performance was more than 10% per year (http://www.moneychimp.com/features/market_cagr.htm). Let's say you're conservative and you go for 6%/year in growth. In 40 years your net worth is $77,737,237.02.
Renting is definitely better than buying in the scenari outlined in grandparent's comment.
Also, I was considering a number of tail risks in our decision. For example, I'd bet that the house in the Bay Area will be worth roughly $0 in 40 years, because:
1.) Tech will have run its course, leading to a Detroit-like situation where everybody moves out and you can't sell what you've got.
2.) The housing stock here is objectively terrible by the standards of anywhere else in the country - many were cheaply built in the 1950s to 1970s, and they need major repairs and upgrades now, let alone in 40 years. Friend of mine was recently buying and was like "I offered $279K over asking on a house that needs at least $100K of repairs", and he didn't get it anyway.
3.) Termites are endemic here. Every house has termites and few of them have concrete basements. There's a good bet that the house you just spend $2.7M on doesn't actually have a foundation.
4.) Earthquakes and wildfires. The big tech companies assume that there is a 100% chance that the Bay Area will be hit by a major earthquake in the next 30 years; I don't see why I should assume any differently.
I moved here in 2009 and there was a big drop in house prices then, enough that everyone who bought in the boom years of 2004-2007 went underwater and many were foreclosed upon. Yes, I'm kicking myself for not buying then - though honestly, the money was in Google stock options instead and Google stock has gone up a lot more than Silicon Valley housing prices, so I probably still ended up ahead.
It's not irrational to want to have some diversification, particularly when things work out fairly well anyway.
My wife and I, despite being able to afford a home, have chosen not to buy one. Why? Because home prices in our area run at $2.7M for a 3BR [1], while we're paying $2600/month to rent a 2BR townhome. People we know who have bought are now paying $6-7K/month on housing, for something not much better than what we have (they have a yard and an extra bedroom, but we have a pool). Even with the mortgage interest tax deduction, you're still paying more on interest alone (let alone principal, property taxes, or maintenance) than we're paying in rent.
[1] This is perhaps an overestimate - it was a news story about a couple that were outbid 4 times and wanted a fairly nice property. But even so, minimum prices on a 2BR condo in the area now range around $1M+, so the math still doesn't work out.