How do I change my icloud
If you want to know your data is secure and don’t trust the passcode to protect it when you sell it, connect to a computer and restore it. 

Otherwise, power it off and then use any computer to remove the lock. 


https://support.apple.com/en-us/HT201441