Unfortunately if you have a forgotten/unknown device passcode, or have a disabled device, you have no option but to erase the device. However, you can eventually restore the data and settings from a backup you made before the device was disabled. You must have a computer to use the method below. If you don't have a computer, borrow one from a friend, or go to an Apple Retail Store or Apple Authorized Service Provider. You will likely also need your Apple ID and password. All Apple mobile devices follow the same general procedure but the link below and other links off it provide model-specific instructions:
If you forgot the passcode on your iPhone, or your iPhone is disabled", click here --> http://support.apple.com/HT204306
'If you forgot the passcode on your iPad, or your iPad is disabled', click here -->
https://support.apple.com/HT211078
Here is a related video which has more complete and clearer instructions: https://www.youtube.com/watch?v=7s8-zLG9ySQ
Steps:
1. With the device disconnected from a computer use the model-specific instructions in the links above to shut down the device.
2. Connect it to a computer with Finder or iTunes (Mojave or earlier, or PC).
3. Restart into recovery mode (black screen with a cable indicating attach to computer).
4. When prompted, click "Restore" to erase data & settings, and update system software. May take some time.
5. Set up your device ( https://support.apple.com/kb/HT202033 ). Partway through you are offered the opportunity to restore your data and settings from a backup, or you can do this at a later stage( https://support.apple.com/HT204184 ). Even if you have no backup, if you were using some iCloud services to sync items such as Contacts or Photos those may reappear once you sign back into your iCloud account --> Set up iCloud on your iPhone, iPad, or iPod touch - https://support.apple.com/HT208681
Read this 'If your computer doesn't recognize your iPhone, iPad, or iPod' click here --> https://support.apple.com/HT204095
---
On the contingency you are asked for your Apple ID and password AND you have forgotten those:
If you forgot your Apple ID, click here --> https://support.apple.com/HT201354 ; your Apple ID password, click here --> https://support.apple.com/HT201487 , or to jump directly to the forgotten sign-in information help site, click here -->- http://iforgot.apple.com/
What to do after [or before] you change your Apple ID email address or password - https://support.apple.com/HT204071
If you still need help, contact Apple for help with Apple ID account security --> https://support.apple.com/HT204169