Because the Ukraine was part, however unwilling, of the USSR. Then the USSR dissolved. Every former country that was part of it wound up with much of the arsenal that was within it's borders. It's not like Russia was the USSR and everything belonged to them (though Russia was obviously the dominant partner). All the republics were part of the USSR and when the whole rotten system collapsed the Ukraine inherited the weapons, both conventional and nuclear, that were within it's borders. Most of these former republics, even to this day, are armed with Soviet era tanks, APC's, etc, that were stored within their territories when the collapse occurred.