How does a double-headed bicycle pump work I have a pump with a presta fitting on one side and a schrader fitting on the other side. If I leave the pump unattached to anything and work the handle, air squirts out both orifices. But if I put my thumb gently over either hole, the pump pressurizes on the side closed by my thumb and no longer squirts out the still-open side. How does this work?

Note 1: This is a double sided head on a stand pump. There is a selection lever but the effect is there without pushing the lever to either side. 

Note 2: There is no need to push a valve into the pump head to see the effect. Blocking a hole by putting a flat cover gently over its outer surface is sufficient.

Note 3: I first noticed this effect when pumping a completely empty tube (outside of a tyre) up from flat. With the valve firmly in the nozzle, and the lever on the correct side, the air insisted on rushing out the wrong (open) side of the pump head. Only when I pressed the tyre rubber almost flat against the inside of the valve, did it build up pressure on the 'right' side and allowed a little air into the tube. That was then sufficient to pressurize the valve so it then pumped all the air out the 'right' side on subsequent strokes.
A small piston or diaphragm is centered by a light spring when pressure is equal and this allows a little air passage opening exposed on both sides. Any pressure imbalance causes the the mechanism to move slightly to one side which closes the low pressure passage and fully opens the passage on the high pressure side.
In physics and engineering this is called an unstable system, a small change cascades to a large change.
The empty tube issue was because the pressure difference was less than the centering-spring preload.
The mechanism could also be a ball rather than piston or diaphragm. Same basic concept as the piston but it uses a ball to close a hole on the low pressure side. In this case more air volume escapes from the open side so the ball gets blown over to that side and plugs the hole which causes pressure to build on the closed side and keeps the ball in place.

It is actually a pretty clever bit of kit, simple, reliable, easy to manufacture.