Resetting your Android device to factory settings erases all data on the device and clears out unnecessary files. The reset process wipes all your information from it, including private data, messages ...
You can unlock your Android phone even if you've forgotten the passcode, but you'll usually need to factory reset the phone.