How Can We Gain Access To Our Device With Forgotten Passcodes? Here's The Solution.
Try DFU (Device Firmware Update) Mode, but putting it in recovery mode is the first step. Unfortunately, yes, it will erase everything on the device, including the passcode. If you have any backups, you can restore it, but a backup may have the forgotten passcode on it again.
You can also try the following:
1. Connect the device to your computer and launch iTunes.
2. Force restart the device. KEEP HOLDING THE BUTTONS UNTIL YOU SEE RECOVERY MODE!
Full details here: https://support.apple.com/en-us/HT204306