This question is inspired by a graph on r/AusFinance called Putting government debt and deficit in perspective. Since this graph goes all the way back to the formation of the Commonwealth of Australia in 1901, it made me wonder where a newly-formed nation's coffers comes from.
It also made me wonder what happened to the coffers of communist nations upon the fall of communism:
Hi, this is regulated by a set of international law called law of state succession, which has rules on succession to a lot of things, for example responsibility; debt and assets and treaties and Human Rights. So i can answer the question from the side of law, of course.
Legally speaking, we have to separate a state succession from an occupation, during an occupation nothing would legally happen to the assets of a state, as it still exists and is just occupied. So the annexation would have to be legal.
I deal with the question of debt succession (to which succession to assets is intimately related) in the 18th and 19th century here, and talk about general succession issues during the breakup of the USSR here.
As mentioned in those comments, succession is currently regulated by the Vienna treaty on Succession of States in Respect of State Property, Archives and Debts (1983), though it lacks ratification so it's unclear what parts of it is customary international law.
It's solution for the "uniting" of states and for a part (territory) of a state joining another state is that the property (assets) of the "uniting" state, or the immovable assets on the territory + the movable assets relating to activity on the territory should pass to the successor state (art. 14 and 16). In relation to a treasury the question would be to what degree the money in question was situated in or related to the territory that joins the successor. What assets a successor state gets must also be seen in connection with what liabilities it takes. if the state takes the debt it should also get the monetary assets meant to cover the debt. Such an idea follows from longstanding legal theory going back to Grotius and Pufendorf.
The rules are quite comparable to in regards to states that separate from an existing state, see art. 17.
So, the short answer is that assets, including monetary ones, in a legal annexation, would fall to the successor state. My two other comments delves more into nuances in the general area of law and the question on the USSR is mostly answered in the other comment, even if i don't talk much about government treasuries specifically.
Some examples: Under the First Vienna Awards Hungary got parts of Czechoslovakias territory in 1938 and succeeded to the assets that had been controlled by Czechoslovakia within that territory.
In the treaties where Spain recognised the independent colonies in the Americas, they generally provided for them to cover debts it had contracted against it's colonial treasuries, as they had been taken over by the former colonies, now newly independent states.
And, as you ask about, the German unification is pretty simple (ignoring disputes about the legal status of Germany and the two Germanies). The united Germany succeeded all property and debt of the GDR. In cases of such total annexation, there is usually no issue. The issue is mainly when one territory joins another state and determining which assets "belong" to that territory.