In the first case you see the $20 and receive the statement. At this point you do not know if the pair of envelopes is $10,$20 or $20,$40 and you do not have enough information to assign a probability to these states.
If you assign probabilities of 0.5 to each state (a Bayesian type of probability) then you can make a decision.
You must switch since by switching you have 0.5 chance of gaining $30 and 0.5 chance of losing $10
Therefore the two cases do not contradict