This shouldn't be happening unless you are pulling off the pump head at an angle. Are you using a floor pump? If so, just be sure you pull the head off straight up. For example, if the stem is at the bottom of the wheel/tire (at the 6 o'clock position), pull it straight up.
I've had the valve come loose maybe twic and both times, I screwd it back in with my fingers.