I can't claim expertise comparing particular funds. But for example, hasn't Vanguard's Real Estate EFT outperformed the S&P 500 by a wide margin?
And beside serious investors, for the typical individual, a home loan allows them to leverage funds that are unimaginably beyond what they could raise for investment with vastly more safety. Not that I suggest it would be better if half the population could and did buy stocks on unlimited margin or the like.
I just want to point out that even on this one particular issue, we gradually made policy and decided and made it such that one kind of loan is vital and the other insanely too risky. That at this point, this is so ingrained that it's hard to imagine any alternative. But I suggest we should probably try.