Spain does appear to have recognized law on their side - it was a Spanish flagged ship, and modern Spain is the recognized successor of historical imperial Spain. But giving the treasure to Spain would be tantamount to endorsing colonial looting.
On the other hand, giving it to anyone else sets a precedent for distributing colonial-era wealth as some form of reparations, and trying to unpick hundreds of years of history and population mixing to work out exactly who should be a beneficiary seems an impossibility.
Maybe it should stay sunken until we have matured a little more as a species.