How do I get rid of someone else’s Apple ID on my iPhone?

How to remove a previous owner’s Apple ID from a used iPhone, iPad, or iPod touch
  1. Sign in to iCloud.com.
  2. Go to Find My iPhone.
  3. Select “All Devices” to open a list of devices linked to their account, and select the device to be removed.
  4. Click “Remove from Account”

How do I delete an iCloud account from my iPhone without a password?

You cannot sign out of or delete an account without knowing the password. That’s basic account security. So you will have to recover the account and reset the password first.