House costs $100k
You buy house with $20k savings and $80k debt
In this example that $80k of debt is called "leverage".
Is this what you mean with your question or did you mean to ask something else?
You have to sell the house, right? So you can only cash in on that leverage when you reverse mortgage or otherwise downsize, right?
(And yes you are also correct it's possible to realize the gains without selling by taking a reverse mortgage.)
So suppose you have $100, and you believe a stock will increase by 10% in value, then borrowing $900 and buying $1000 of the stock, will leave you with $1100 if your prediction is true. When you pay off the loan, you'll be left with $200, and you will have doubled your money.
The loan thereby acts as a leverage multiplying the 10% return on investment to in this case a 100% return on investment.
Now imagine that instead of having $100, you have $50k, and instead of borrowing $900, you borrow $450k, and instead of buying stock, you buy a home with the 50k deposit and 450k mortgage. The same applies, the home appreciates 10% to 550k, but your equity increases from $50k to $100k. Again, the mortgage loan acts as a lever.
The difference is that most consumers do not have large and cheap capital available to them, say to borrow $450k to invest in the stock market. But most people do have such opportunities to invest in the real estate market with a mortgage.
Anyway, wether it's a good investment really depends on many factors. The NYT buy or rent calculator is still one of the best sources to get an intuition on what is best for your circumstance. https://www.nytimes.com/interactive/2024/upshot/buy-rent-cal...