While true, this requires them understanding that it is an illegal order in the first place, and suffering the consequences of that action in the meantime. Just because they're following the law and doing the right thing, they most likely will still be punished in the short term for not following orders, even if those orders end up being determined to be illegal.
Similar to being illegally detained and arrested by police. There is not much you can do about it at the time, fighting with the officer will only make it worse. You argue the legality of it after the fact.