Open Settings
Tap your name at the top
Scroll down and tap Sign Out
Enter your Apple ID password if prompted
Turn off Find My iPhone if asked
Choose the data you want to keep on the iPhone
Tap Sign Out again to confirm
If you cannot sign out, go to Settings > General > Transfer or Reset iPhone > Erase All Content and Settings
If Activation Lock is enabled, sign in with the Apple ID and password before removing it
If the Apple ID is not yours, contact the previous owner to remove the device from their account
If needed, remove the device from iCloud.com under Find Devices or Account Settings
