This is not the authoritative answer with references that Grade'Eh' Bacon desires and I don't expect any bounty for it. There are a lot of gray areas in this matter....
The OP was a long-term resident of the US, but not a green-card holder, and has recently returned to Australia which is his country of citizenship. He believes that he is exempt from paying US capital gains tax on sales of stock held in the US after his return to Australia on the grounds of not having any connection with the US anymore. However, the governing regulation seems to be IRC Section 7701(b) which says that he was nonetheless a resident alien during that time. Under IRC section 7701(b), a resident alien is either 1) a lawful permanent resident (i.e., a green card holder) or 2) an individual who is “substantially present” in the United States, and the OP certainly qualified as a resident alien under 2). Furthermore, since the OP moved back to Australia some time during 2021, the IRS deems him to be a tax resident of the US for all of 2021. The OP ceases to be a tax resident of the US when he
(i) commences to be treated as a resident of a foreign country under the provisions of a tax treaty between the United States and the foreign country,
(ii) does not waive the benefits of the treaty applicable to residents of the foreign country, and
(iii) notifies the IRS of such treatment on Forms 8833 and 8854.
Now, I don't know anything about the tax treaty (if any) between Australia and the US, but most tax treaties say something like each country will tax the income generated within its jurisdiction only, and if one country (usually this means the US) taxes income generated in the other country, then it will give credit against the income taxes due to itnfor taxes paid to the other country. This avoids double taxation of income and effectively means that the _total_tax due from the taxpayer is the larger of the taxes charged by the two countries. So, assuming that the OP follows items (i)-(iii) above, then if and when the OP realizes the capital gains of $900,001$ in the US, he will owe income tax to the US on that amount (presumably a long-term capital gain) less the capital gains tax on $1 that he will pay to Australia.
What if the OP chooses to waive the benefits of the US-Australia tax treaty (or there is no US-Australia tax treaty at all)? Then, I believe that IRC 877A applies. This imposes a mark-to-market regime, which generally means that all property of a covered expatriate is deemed to have been sold for its fair market value on the day before the expatriation date. Any gain arising from the deemed sale is taken into account for the tax year of the deemed sale notwithstanding any other provisions of the Code. Any loss from the deemed sale is taken into account for the tax year of the deemed sale to the extent otherwise provided in the Code, except that the wash sale rules of IRC 1091 do not apply._ So it appears that the OP will not owe any capital gains tax to Australia except for the increase in value from his deemed acquisition as of the date that he landed in Australia, but he does have to pay US capital gains tax on the deemed sale of his shares in the US without actually selling the shares. Moral: the OP should sell enough shares before year-end so that he will have enough money to pay the capital gains tax owed to the US. Actually, he probably needs to file Estimated Tax returns (Form 1040-ES) if his unrealized gains really are $900K.
What you gain on the swings, you lose on the roundabouts.....