macOS switches to Bluetooth headphones automatically
You can consider setting your Mac not to auto-connect to Bluetooth headphones, using this command in Terminal:

sudo defaults write /Library/Preferences/com.apple.Bluetooth.plist DontPageAudioDevices 1


This will not interfere with Apple Magic Mouse, Keyboard or Trackpad. Only audio devices will not be auto-connected.