Headphone jack broke and got stuck in headphone socket MacBook Pro
Solution 1:
Depending on the breakage, you may not be able to control the software if the "jack detection" sensor is intermittent. It will over rule whatever software setting you have made and send output to the headphone jack each time it senses an insertion.
Often taking this to Apple at a genius bar is no cost if they can dislodge the broken piece with experience (and same for reputable repair shops). Also, you might only pay labor if the jack isn't broken. Usually there is more damage since why would a protected piece break off inside a perfectly functioning receptacle, but it's possible you broke the jack mostly or entirely before inserting it.
Give a shot at setting the sound in the System Preferences, but most of the times this happens, you'll need to get a repair if you can't use software to switch the output once and have it stick.
Solution 2:
if you get a 3.5mm jack broken inside the headphone socket, to remove the broken jack, take out the ink tube from a bic pen, you gently push the ink tube into the headphone socket, (use the end that is not used for writing). i would push about 1/2 to a inch in, then pull it out the ink tube and out comes the broken jack.