Somewhat more outrageous is the 1031 exchange. Sell VTI at a profit to buy VOO and the government hits you with a capital gains tax. Sell your primary residence for $250k more than you bought it - same thing. But landlords are a special, privileged investor class to whom these rules don't apply. They can sell a house and pay no taxes on gains as long as they buy another property.
This is also not really how depreciation works for assets that retain their value. If you buy a building to rent it out, the cost of the building essentially a cost of doing business, i.e. a tax deduction. You pay tax on the profit which is revenue (rents) minus costs (building, interest, maintenance, advertising, etc.) Depreciation is the building, they make you take it over time instead of all at once when you buy it.
But the depreciation lowers the book value of the building, which is your tax basis when you sell it. If you buy a building for a million dollars, depreciate it down to $500,000 and then sell it for $2M, you have a $1.5M capital gain from the sale. You basically have to give back all the depreciation unless the building actually lost that much value by the time you sold it, and in practice it usually goes up instead of down.
It's really the homeowners who have the advantage here because there is a large capital gains tax exemption from the sale of your primary residence, and that's actually a reduction in taxes instead of just a deferral.
Homeowners get a tax exemption but only up to a certain amount in gains.
They can also keep the property forever and continue renting it out, and then never realize the gain. But in both cases that means they don't get to realize the gain -- or even recover their original principal -- except insofar as they're renting it out, and the rent is taxable income.