Question: why does my iphone only charge when locked?
Answer: Apple describes it as a new “security protection” that's introduced as part of iOS 11.4. ... USB Restricted Mode works like this: after an hour of your iPhone, iPad, or iPod Touch sitting without being unlocked, iOS will basically cut off the Lightning port and limit it to charging only.