MacBook Air headphone jack causing mac to go into sleep mode
Generally speaking, the MacBook Air has a MagSafe DC In board that also has an audio connector.



It's very conceivable that there is a broken connection on this board that "fixes" itself when you put pressure on the headphone jack.  Technically you could fix this, but it's probably simpler to just change this board out.

If you provide me with your specific make and model, I will provide you with a more accurate PN# and a link to the repair documents.