But then they bought it again. They had 129 tons of gold, and now they still have 129 tons of gold. Where does the realised gains come from?
From paper shenanigans. Don't expect accounting spreadsheets to perfectly mirror real life. Most of the financial economy is kayfabe.
Let's say I bought a 100-ounce gold bar in 1965, when gold was $35/oz, for a total price of $3500. Let's say I sold it today at $4700/oz, for a total price of $470,000. That gives me a gain of $466,500.
And let's say that I regret it. I decide that I really want to hold some gold, so I take the $470,000 and buy another 100-ounce gold bar.
The situation was that I had a gold bar worth $470,000 with a taxable basis of $3500. Now the situation is that I have a gold bar worth $470,000 with a taxable basis of $470,000, and I owe the IRS taxes on $466,500 of capital gains.
TL;DR: Selling and re-buying the same asset gives you the accumulated gains, and resets the price basis.
The variation in gold prices in the time they carried out this exchange process.
They "realized" it just for a short time.