If you have a forgotten/unknown device passcode, or have a disabled device (device unavailable or lockout screen), you unfortunately 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, or if you were using iCloud to store that data. If you end up having to use a computer and you do not have one, borrow one from a friend, or go to an Apple Retail Store or Apple Authorized Service Provider. You can also use a PC with iTunes. 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, provides system and model specific instructions:
If you forgot your iPhone passcode or your iPhone is disabled - Apple Support
If you reset your passcode in the last 72 hours and have forgotten it, read this article about a special reset service available in iOS 17 and higher. --> Temporarily use your old passcode when you forget your new passcode on iPhone or iPad - Apple Support
If this is accidentally happening in your pocket, get a better case or stop keeping it in your pocket.