The consequences for following an illegal order include being sued, being held in contempt of court, or being criminally prosecuted by a subsequent administration. They don't have the same immunity that presidents do because they don't have a direct vesting of authority under Article II.
Ok? The question is, in what sense are they allowed to refuse an illegal order, given that the consequences are the same as refusing to follow a legal order?