Not to prevent our souls leaving our bodies, as some traditions would have it. The gasp which causes our mouths to open when we are shocked is a fast, deep in-breath that evolved to provide a quick burst of extra oxygen to help deal with startling events. This makes the mouth vulnerable, so covering it may be a protective gesture. It is also a way of concealing our emotions from others, to avoid showing that we are afraid, shocked or disgusted. Many experts say that the response is learned as a form of politeness but, like many other gestures, this behaviour is seen across various different cultures. So the reaction may have some inherited basis, but in modern times it may often just be a way of hiding the fact that you were startled by nothing more serious than a fly, or shocked by what your friend said.