Because they never realize capital gains. Instead they take a loan and use the stock as collateral to get
liquidity . They never pay back that loan, but just pay interest, which again lowers their taxable income.
I'm not sure how, but the "margin debt is an infinite free money hack" somehow caught on and won't go away. It's not a free money hack, it's debt that must be repaid with income. Which is always taxable.
Additionally, the wealthy will usually leave only enough assets in the estate to cover the liabilities plus maybe some more up to the estate tax threshold so it goes through tax free to the heirs. The rest will have been distributed through various other methods to avoid taxation.
There is also jurisdictions were there is no inheritance tax, which would otherwise require to sell at least some of the estate.