Soldiers are indoctrinated into obeying orders despite their best judgment. That's how human beings convince other human beings to voluntarily lay down their lives in someone else's interests and against their own.
They are also told in no uncertain terms that they'll face prison or execution if they refuse to obey.
So while they are cutely told they have a duty to disobey illegal orders, practically they are heavily biased towards doing the exact opposite.