Ordering the nuking of a US city would certainly be an illegal order. Not sure about your second example.
Bombing dams to send a message would be grossly disproportionate and probably a criminal act. Doing so to destroy enemy industry during a war is legal.
I once sat in on a long, hypothetical discussion during an exercise concerning when dams could be bombed and when they could not. A general, bunch of Colonels, some lawyers, etc. That was probably why that particular inject to the exercise was done. Those of us who flew and dropped bombs tended to be on the “Just drop them!” side, while the lawyers discussed what would or would not make it legal.