Question: why does my iphone not charge when locked?
Answer: “If you don't first unlock your password-protected iOS device — or you haven't unlocked and connected it to a USB accessory within the past hour — your iOS device won't communicate with the accessory or computer, and in some cases, it might not charge,” reads Apple's support page on the security feature.