I have a very similar problem; I use a dongle (usb-c -> 3.5mm jack) to connect headphones and listen to music and it stops working when the phone gets locked (either manually or automatically). The only (impractical) solution I found was to plug the dongle while the phone is unlocked and under "security" -> "screen locking" temporarily set the delay for "autolock after sleep" to 30mn instead of "instantly" and also disable "lock instantly using the power button", and revert these settings when I'm done using headphones, which is really less than ideal...