Headphone jack broke and got stuck in headphone socket MacBook Pro
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.