Will it stay in the gold mines until it's upgraded? Or will it vanish?
When you upgrade the gold mine, all the resources will be lost. It will be emptied and attackers will not be able to steal any of it.
As seen on the wiki:
Note that if your Gold Storages are full at that time, the uncollected gold will be lost!
If a Gold Mine is destroyed in an attack while it is being upgraded, no gold will be lost, as the mine is empty during this time.
Note that this applies to all three collectors: Gold mines, Elixir collectors and Dark Elixir drills.
Your gold will stay in the mines because you cannot fit any in your storages.
Normally, when you upgrade a resource collector the resource will go into your storage once the upgrade starts. In this case the gold will stay in the mine.
However, because there is still gold in the mine raiders can steal gold from it until it is empty.