log out of iCloud
in settings choose erase all
do to wipe data
Sign out on your iPhone, iPad, or iPod touch
If you use iOS 10.3 or later:
Go to Settings > [your name].
Scroll down and tap Sign Out.
Enter your Apple ID password and tap Turn Off.
Turn on the data that you want to keep a copy of on your device.
Tap Sign Out.
Tap Sign Out again to confirm that you want to sign out of iCloud.
If you use iOS 10.2 or earlier:
Go to Settings > iCloud.
Scroll down and tap Sign Out.
Tap Sign Out.
Tap Delete from My iPhone.
Tap Keep or Delete for data on your iOS device, such as iCloud calendars, Safari data, reminders, and contacts.
Enter your Apple ID password, and tap Turn Off.
How to erase your iPhone, iPad, or iPod touch
Tap Settings > General > Reset
Then tap Erase All Content and Settings.
If asked, enter your passcode or Apple ID password
Then confirm that you want to erase your device.
Wait for your device to erase
Depending on your device, it can take a few minutes to completely erase your data.