Once upon a time, long long ago, in a land far, far away, I was leading a flight of AH-1G Cobras in support of ground troops attacking a village. The ground commander, who outranked me, directed me to unload our ordinance on said village. Now this wasn't all that unusual, but after giving instructions on how we would proceed with the attack, one of my flight leaders, a sharp first lieutenant, came on the radio. He said "Red (my call sign), you know they are court marshalling people ( Lt. Calley) for this back in the world." Darn good point!
The ground commander was in charge of and supposedly knew the situation and it wasn't an illegal order, but the potential for repercussions was there. So I simply radioed him to confirm there were no civilians left in the village. Which he did. Problem solved.
And remember the John Wayne movie where he was a Cavalry officer fixing to retire and he gave a couple of Lieutenants an order and put it in writing so it would help at their Court Marshall if there was one? The Nuremberg Defense I know, but there are ways to defend your actions in questionable situations.
I think, as if anybody cares what I think, that an illegal order is one that leaves no doubt, to virtually anyone, that it is illegal. Like killing non-combatant children or the situation GB posted about. But there are those nowadays that are trying to pervert that clear definition into "anything that doesn't feel right to me" is an illegal order.