In some cases, it can take quite a number of attempts to get that to work. I have read some anecdotal evidence that it took a dozen or more tries before the device and iTunes would respond.
Did you try erasing with iCloud?
If you set up Find My iPhone on your iOS device or Mac, you can use iCloud to erase and restore it.
- From another device, go to icloud.com/find.
- If prompted, sign in with your Apple ID.
- Click All Devices at the top of your browser window.
- Select the device you want to erase.
- Click Erase [device] to erase your device and its passcode.
- Now you can either restore from a backup or set up as new.
If your device isn't connected to a Wi-Fi or cellular network, you can't erase it with Find My iPhone.