AirPods are designed to move automatically between Apple devices signed in to the same Apple Account, but that convenience can become annoying when they jump to a Mac or iPad you were not trying to use.
You can make AirPods less eager to switch without turning off Bluetooth or unpairing them. On iPhone or iPad, connect your AirPods, open Settings, tap their name, then look for the connection setting that controls when they connect to that device.
Changing the option from automatic switching to the setting that reconnects only when they were last used with that device can make the behaviour much more predictable.
The same idea applies on Mac. With the AirPods connected, open System Settings, select the AirPods and adjust the connection preference there.
This is particularly useful if you keep a Mac on your desk playing occasional notification sounds while mainly listening from your iPhone. Automatic switching can interpret activity on the Mac as a reason to move the AirPods, even when you would rather leave them connected to the phone.
You do not have to make the same choice on every device. You can leave automatic switching enabled on the devices where it is useful and make one troublesome Mac or iPad less aggressive.
The result is still a seamless Apple setup, just with fewer unexpected interruptions.