Man, I wish my headphones did this. I constantly have to fiddle with my bluetooth settings, have audio come out of my mac or iPhone, sometimes in inappropriate places, even after I've tried to tell the OS to play from headphones. The worst is when switching between my Mac and iPhone, usually I have to unpair one, put my headphones into pairing mode, or at the very least turn bluetooth off on one device.
My headphones are...Apple AirPods. They did this when they first launched, so I even got the pros. Now none of my pairs ever work.
I really wish Apple would figure out how to make stuff just work. I think there's opportunity for someone to figure it out! No clue what happened to this company, but the AirPods are undoubtedly the most frustrating Apple product I've ever owned