Worth noting Android (or at least Pixel) does have a feature like this, but it actually does the opposite: while a Bluetooth device is connected it keeps the phone unlocked. It would be way more useful in the reverse: that if a Bluetooth device disconnects, it should lock.
These are two different things, since I do not want my phone to have no lock screen just because my headphones are sitting near it, but if it is unlocked and suddenly my headphones disappear, that would be a useful precaution, even if it doesn't eliminate the risk on its own.
It's called Android Smart Lock and has been a thing since Android 5 (Lollipop). It also works (worked? Does it still exist) with 'trusted places' (GPS/WiFi), Voice/Face (before face id was a thing) and a mode were it kept the phone unlocked as long as you kept it on your body.
I remember that I used the last option many years ago, as that was really convenient and worked very well. Basically as long as the phone was in your hand or pocket it kept unlocked, but as soon as you laid it on a table it got locked.
But now that fingerprint unlock is a thing, I don't even mind unlocking my phone as it is one fluid motion and happens unconsciously.
These are two different things, since I do not want my phone to have no lock screen just because my headphones are sitting near it, but if it is unlocked and suddenly my headphones disappear, that would be a useful precaution, even if it doesn't eliminate the risk on its own.