Back up your iPhone if needed
Sign out of Apple ID and disable Find My iPhone if possible
Open Settings
Tap General
Tap Transfer or Reset iPhone
Tap Erase All Content and Settings
Enter your passcode or Apple ID password if prompted
Confirm the erase
Wait for the iPhone to restart and erase
Set it up as new or restore from a backup
