When GL_DEPTH_TEST is enabled, the depth of incoming fragments will be tested against the current depth in the framebuffer, using the function specified with glDepthFunc. Fragments will be discard or accepted based on that test.
When glDepthMask is set to true, any fragments that make it to the end of the rendering pipeline will update the framebuffer with their depth.
This is useful when doing a Z pre-pass. In the depth pass, GL_DEPTH_TEST is enabled, glDepthFunc is set to GL_LEQUAL (or GL_GEQUAL, depending on the setup) and glDepthMask is set to true. In the shading pass(es), GL_DEPTH_TEST is again enabled, glDepthFunc is set to GL_EQUAL and glDepthMask is set to false. Doing no depth writes in the shading pass(es) saves framebuffer bandwidth.