Internal speakers are cut off when the headphones are connected. That is done by a leaf switch in the headphone socket which is pushed aside when the jack is inserted.
If it doesn't revert to the internal speakers when the jack is removed, it's likely that that switch has stuck (this is not uncommon). If that's the case, a red light will be visible in the socket (that's the digital fibre optic output).
Try inserting and removing a jack a few (dozen) times.
If that doesn't free it you may attempt to tease it with a slim non-conducting tool (like a toothpick). Ensure the Mac is not only shut down, but unplugged if you try this.
And be careful; the leaf is fragile and it's an expensive bit to get to and replace, in fact on some models it's directly on the logic board.