Before completely deleting the iPhone or iPad, you should first create a backup. (How do I create an iOS backup?)
If an Apple Watch is paired, it must now be unpaired. If notes, photos, address book, etc. have been synchronized with iCloud, please next "Find My iPhone“ in iCloud, then the iCloud account can be disconnected from the iPhone / iPad. It would also be advisable to deactivate iMessage and Facetime.
Now the iOS device can be reset. To do this, go to "Settings", tap "General", scroll all the way down and click "Reset". Now you have to tap "Reset all settings". The iOS device will now be completely erased, which means that all data will be removed and all configurations will be reset.