Set audio input/ouput device priority
Posted as answer just to be able to inline pictures...
Not really sure how to test this, as I don't have a Macbook - but what happens if you use Audio Midi Setup & mute the unwanted output? It might then skip it when you unplug the headphones.
…or possibly setting up a Multi-Output device, set to be your default output, with only the used connections checked…