But you pay interest on your leverage. So if your asset isn't appreciating faster than inflation + your interest rate then I don't think you're actually realizing any gains.
Not necessarily true because you are covering your need for housing at the same time as paying the mortgage. So even if it appreciated exactly at the same speed as inflation(as one would expect if housing prices were flat) you are only paying the interest rate but gaining an asset at the end of the mortgage. Also, that asset theoretically allows you to cover your housing needs for the rest of your life(with appropriate maintenance), so it should be valued as potential sale price + the value of owner's equivalent rent for the rest of your natural life.
This is what is different about real estate from all other investments -- you have you put your money towards it, whether it's an investment or not. You might not realize any gains on a mortgaged property, but it could be a better hold of money than rent.
You need to subtract the rent you're saving from the interest and also need to take into account if you can deduct the interest from your taxes [1]. If that interest rate ends up lower than inflation, you're realizing gains.
Even then, this assumes you'll have enough deductions to not take the standard deduction. I did this analysis once. I took the cost of a rental I was considering, figured out how much I claimed on long-form taxes. Then I re-calculated using the standard deduction (loss of housing interest deduction meant standard deduction was better for me). Then used the tax difference spread out over 12 months to calculate the "true" cost of my mortgage. It turns out the mortgage was quite a bit cheaper.
Even still, though, I am taking on a risk of not being able to sell the house if I ever change jobs. It's appreciating rapidly right now, but everyone knows this can change in months.
Note that primary residences in the US also have very preferential treatment as far as taxation of capital gains goes. That means that owning a house is a lot better than owning pretty much any other asset that only appreciate at the inflation rate.
That's only true if you just let the property sit there without taking advantage of the potential ways it could produce income for you (e.g. rent). On the flip side, you also need to consider property taxes, maintenance, insurance, etc.