The most common mistake when selling a phone is going straight to “reset to factory settings”. This deletes the record of the files, but on some devices the data can be brought back with recovery software. What's more, if you reset without signing out of your account, the device may not open for its new owner because of an account lock.
The right order is this: backup first, then signing out of your accounts, then encryption, and resetting last.