Is the iPhone on the security lockout screen? You will need to erase the iPhone in order to remove the passcode.
How to reset your device in iOS 17
If you're using an eSIM on iOS 16 or earlier, contact your carrier before trying these steps and ask for a QR code to set up your eSIM again.
- From your device's Lock Screen, try to enter your passcode until the "[Device] Unavailable" screen appears and your device asks you to try again later.
- When you're able to, tap the Forgot Passcode? option in the bottom corner of the screen.
- On the Security Lockout screen, tap Start [Device] Reset to confirm.
- Enter your Apple ID password to sign out of your Apple ID on your device.
- Tap Erase [Device] to permanently delete all of your data and settings. If you use an eSIM with iOS 17 or later, you can also choose to keep your eSIM and erase your data, or to delete your eSIM and erase your data.
6. When your device restart, follow the onscreen instructions to set up your device again, restore your data and setting from a backup, and set a new passcode.
If you can't follow these steps, you can use a computer to reset your device.