Note that it behaves subtly differently to how you described in case it was connected to something before being locked. In that case data access will remain -- even though the phone is now locked -- until the device is disconnected.
Anyone can do this for over a decade now, and it's fairly straightforward:
- 2014: https://www.zdziarski.com/blog/?p=2589
- recent: https://reincubate.com/support/how-to/pair-lock-supervise-ip...
This goes beyond the "wired accessories" toggle.
Set to ask for new accessories or always ask.
The lack of optional granularity on security settings is super frustrating because it leads to many users just opting out of any heightened security.
It's "attached" to the wifi and to the cell network. Pretty much the same thing.