Enter settings and go to Face ID & Passcode or Touch ID & Passcode. You then need to turn on USB Accessories under Allow Access When Locked. When the UBS Accessories setting is turned off, you will have to unlock your device to allow a USB accessory to connect.