Here are the steps for you, when you forgot iPhone passcode:
Step 1: Connect iPhone to computer via a USB cable> launch iTunes on computer.
Step 2: When you launch iTunes, it will automatically sync your device. But if it doesn't, you need to do it on your own, which means you have to do the following steps: Click "View"> "Show Sidebar", then your iPhone will be displayed in the left sidebar.
Step 3: When iTunes have synced and backed up your device, please go to "Device" in the sidebar. Then click on Summary tab. Next go to "Restore iPhone" button.
Step 4: Finally, click on "Restore Backup" to restore iPhone from iTunes backup files and then you can reset your iPhone passcode.
Hope it can help you and if you found data loss of your iPhone, you can choose FonePaw iPhone Data Recovery to recover lost data.