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.