Nuclear weapons are illegal in two ways:
(1) The Geneva Accords (to which the U.S. is a party) specify that during any war, although international law allows targeting and killing combatants, nations are prohibited from using weapons that do not distinguish between combatants and civilians. Using nuclear weapons would certainly violate international law. Also, I remember that in 1996 the International Court of Justice issued an advisory opinion stating that while merely possessing nuclear weapons is not illegal, actually using them would be illegal.
(2) Thus far, 69 nations (but none of the 9 nations owning nuclear weapons) have ratified the Treaty on the Prohibition of Nuclear Weapons (TPNW). Nuclear weapons – in fact, any activities supporting them – are illegal in those 69 nations. It went into effect after the 50th nation ratified it. Let’s keep promoting the TPNW to urge more nations to ratify it.