Views:

Sign Out of iCloud on iPhone 
 

1. Go to Settings, then tap your name

2. Scroll down and tap the Sign Out button.

3. Enter your Apple ID password and tap Turn Off

4. Tap Sign Out.

5. Tap Sign Out again to confirm that you want to sign out of iCloud.
 

Once you sign out from your apple account completely then follow factory reset steps.


Factory reset

1. Go to Settings > General > Transfer or Reset iPhone

2. Select Erase All Content and Settings

 

  1. You'll need to enter your phone's PIN code along with your Apple ID password to remove the phone from your account.
  2. After entering your password, the screen will go dark and the Apple logo along with a progress bar will show up. A few minutes later, you'll be greeted with a screen with "Hello" in different languages flashing on it, indicating the reset was a success. 

Reference

How to factory reset your iPhone, iPad, or iPod touch - Apple Support