Whenever I wash my thermos, I put hot water and then some soap in; then I seal the one end with my hand or use the lid. After shaking it up, if I slowly remove the lid or my hand, it expels a little air. Why is that? Does it have something to do with increased surface area of soapy water? Or is it the fact that the air is heated by the water, even though the water must surely cool slightly?
When you pour the hot water in, the air inside the thermos is still quite cold (ambient temperature, approx.)
But then when you shake it up the cold air is heated by the hot liquid. Gases expand considerably when heated, approximately acc. the Ideal Gas Law:
This causes a modest (and harmless) pressure increase in the flask, which is what you experience.
There is another effect here which is significant, as follows.
Warm water wants to evaporate, but in a flask-shaped container, the evaporation can take place only at the free surface of the water in the flask. Furthermore, as soon as the boundary layer of air right next to the warm water becomes saturated with vapor, the diffusion of water vapor into the air slows down greatly.
If you close the container and shake it vigorously with soap added, tiny air bubbles get mixed into the warm water, producing a huge surface area available for evaporation to occur across. The bubbles expand as they get loaded with vapor and the pressure inside the container jumps up suddenly.