It appears that you had reset the passcode on your iPhone. As you have learned, that process deletes all data on your iPhone.
——
If you deleted your messages while using iOS 16 on your iPhone, then you can check by tapping on the EDIT button in the Messages app and then Recently Deleted Messages. If there are no deleted messages then Recently Deleted option will not appear. If your deleted the messages while using a previous version of iOS, then read below:
________________
Recover Deleted Texts
If iCloud is set to ON for text messages and you deleted some text messages then they are gone from iCloud so cannot retrieved! If this is the case then it is all over and no need to read further. You can double check by opening Settings ➡️ Apple ID (Your Name at Top) ➡️ iCloud ➡️ Messages: If this switch is set to ON, then you are using iCloud for Messages.
If you do not use iCloud for text messages then you can restore your iPhone from a backup on your iCloud account (if you use iCloud to back up your iPhone). Once you restore then your texts will only be as current as when the back up was created. Here is 👉 How to restore your iPhone from an iCloud back up.
The other option is to restore your iPhone from a backup that you may have created on your computer. Once again, if you restore your iPhone from a computer back up then your texts will only be as current as the day and time the backup was created.
If you have a backup created on your computer and If you choose to restore your iPhone from your iPhone from it then here is how to do it 👉 Restore your iPhone, iPad, or iPod touch from a backup - Apple Support
Axel F.