The law of "civilized" western nations (incl the USA) has often held that indigenous peoples had no individual ownership of property and therefore was never subject to the sovereignty of any state prior to "ownership by conquest" by a western nation. This has often been used in Australia against aboriginal land claims and by the US Supreme Court in the case of in the Johnson v. M'Intosh case, (see 21 U.S. (8 Wheat.) 543 (1823)), that held that private citizens could not purchase lands from Native Americans since they did not "own" it until a nation took it.
This legal theory is termed "terra nullius" and thus could be used by a spanish (or even US) court to claim the native peoples did not own the gold until it was acquired by conquest. Therefore the Spanish government may have "good" title to the gold relative to native american or even the claims of latin American countries.
I admit there is a distinguishing fact between land rights and gold rights, but this legal theory can certainly be claimed and possible upheld by the courts.
I am not saying this is right, just saying this is how western powers have supported each other in the past. So to speak Spain is "part of the club" recognized as "owning property," but the Inca people of Peru perhaps not belong to the club of property owners. This has been heavily criticized by legal academia (see for example Prof. Stuart Banner at UCLA School of Law, as "rooted in a Eurocentric view of the inferiority of the Indian people" in "How the Indians Lost Their Land: Law and Power on the Frontier" (2005), p. 11--12).