The slightest movement of my cable on my headphones causes the connection to fail and the MacBook reverts to the internal speaker.
Most annoying. It’s been like this for a long time, years, maybe the whole time I’ve had the laptop.
It turns out that this is a common complaint, and the solution is to replace the logic board (!) presumably with one that has a different connector, or to hack it with a tiny sliver of aluminium foil,
Take a VERY tiny piece of aluminum foil and fold it up so its thickness is equal to the distance that your headphones pull out of the audio jack on the macbook when gently pulled. On mine, it’s probably half a millimeter.
Your aluminum square should only be large enough to fold over the bulbous tip of the 3.5mm plug. Do not make it so large as to cover any of the colored lines on the tip of the plug. Mine was about 4mm wide (go figure, it’s a 3.5mm plug).
Insert the plug with the aluminum cover all the way into the socket. When you pull it back out, the aluminum should stay in down at the bottom of the plug; it will serve as a spacer so there is no longer a gap in the slightly larger microphone/audio dual plug on MacBooks (made to be compatible with the Apple audio/mic headseats).