There is no guarantee that the current market-clearing price for a given object is equivalent to that at which a larger inventory can be sold.
Taxing capital gains at the time of sale makes sense -- there is actual revenue available for taxation. Taxing unrealized gains can be a path to really-negative outcomes. This is particularly so if the government doesn't give matching credits for unrealized capital losses.
This keeps people's capital invested longer term, which is part of the purpose of capital gains tax incentives.
In other words, it's not a loophole. It's working as intended.
I'm no expert, but I would guess that, if shares are foreclosed upon, the bank's basis is zero (and their taxation short-term)?
(Edit: the downside here is that the government doesn't see any revenue from this approach, which it might otherwise. The shareholder must pay interest, though, which might not be to their advantage.)