Bluetooth connection never works on first try, but works on second try

I have some bluetooth earphones that work perfectly everywhere else I try to connect them to, except for my laptop.

Basically what happens is that whenever I take them out of the case they connect automatically and at first sound works fine. Then after a few seconds of so the sound automatically switches from the bluetooth earbuds to the laptop. When I check the laptop configs I see that the bluetooth earphones are still connected, but the option to switch the audio output to bluetooth no longer exists. Again, while bluetooth is still connected.

Then I manually disconnect bluetooth and connect it again and then everything works as normal.

What’s going on? And how can I diagnose it?