That's not accurate. It has several benefits (like interest payments being deductible expenses) and wealthy people can continuously borrow to pay off other debts as their other assets appreciate. You just need the rate of appreciation of your assets to be higher than the interest rate. For very big loans, it's quite possible.
Finally, it's also possible to roll the gains into a trust and the cost basis is adjusted to zero on death. [0] So yes, it's tax avoidance.
The above basically arbitrages long-term vs short-term capgains for the price of 1 APY cycle, right? That's ~23% for short in the USA, and up to income-level (37%?) for short-term. Quite a big difference for a 2-5% APY loan that you close after 1 year, and the numbers would seem to scale better the higher you go.
The theoretical assumes SPY increased over the time period. If it decreased, you could of course sell it and pay 0% since your investment lost money, short/long-term gains wouldn’t matter because there wouldn’t be any gains.
2) You're buying a house, and you need $100 today.
3) You sell $100 of SPY, and pay short-term capital gains (up to 37%)
OR...
1) You purchased $100 of SPY on June 15th, 2020
2) You're buying a house, and you need $100 today.
3) You take a loan for $100
4) You wait until June 15th, 2021 and then sell $100 of your SPY holdings, paying long-term capital gains (15-20%)
5) You repay the $100 loan
...it doesn't really avoid tax. It's just an alternative way of accessing capital by taking out a loan instead of liquidating assets.