Question: how to unlock an iphone when it is locked?
Answer: On your computer, start iTunes and connect your iPhone using a USB cable.
Start your iPhone's recover mode. ... 
On your computer, click "Restore." ... 
After this process completes, your iPhone will be reset to its factory conditions.