They weren’t under the control of the Ukrainian government.
By your logic, Turkey has nukes because the US has nukes on a base there.
The Soviet Union had broken up and the nukes were on Ukrainian soil and under control of Ukraine. Now go look up the Budapest Memorandum.