I am not saying you implied the Iraq war is illegal, only that your assertion that legal orders resulting in illegal actions in today's environment make the situation more complex.
I disagree, the illegal actions of the Marines in your example could have happened whether or not the order was given. The original legal order was only a contributing factor, there is no direct cause and effect.
There will always people who don't understand and/or don't obey the rules, their orders, etc. Just because a legal order proceeds them does not cast any shadow of doubt on the legal order or the officer that gave them.
The bigger picture is that just because some individuals, be they in the CIA or the Army, break some rules, law, etc. and participate in "terrorist like" acts, and their actions were preceded by legal orders, does not mean that the CIA and the Army are terrorist organizations. I know you are not personally accusing them of such, just that the logic doesn't hold.
Example: Members of a local Wal-Mart are members of a criminal enterprise, assume it even involves a couple members at corporate Wal-Mart. Let's say they associate on a continuous basis, form an allegiance for a common purpose, and are involved in criminal activity. By the logic being used, then Wal-Mart would be considered a gang.
The bad acts of a few individuals, at any level of an organization, do not override the overall intent and mission of the organization as a whole.