"Remove your passcode
If you backed up your device, you can restore your data and settings after restoring your device. If you never backed up your device before you forgot your passcode, you won't be able to save the data on your device.
- You need a computer to follow these steps. If you don't have a computer, borrow one from a friend, or go to an Apple Retail Store or Apple Authorized Service Provider.
- Make sure that your device isn't connected to your computer, then choose your device below and follow the steps:
- iPhone X or later, and iPhone 8 and iPhone 8 Plus: Press and hold the Side button and one of the volume buttons until the power off slider appears. Drag the slider to turn off your device. Connect your device to your computer while holding the Side button. Keep holding the Side button until you see the recovery mode screen.
3.Locate your device on your computer. When you see the option to Restore or Update, choose Restore. Finder or iTunes will download software for your device. If it takes more than 15 minutes, your device will exit recovery mode and you'll need to repeat steps 2-4.
4.Wait for the process to finish. Then you can set up and use your device.
Also, see this before selling your phone: What to do before you sell, give away, or trade in your iPhone, iPad, or iPod touch - Apple Support
-AJ