Only if your text messages have been saved on your mobile phone, there's a way to recover them. In case you saved them directly on the SIM card and not on your mobile phone, you'll not be able to recover those messages.
To recover your text messages, you can restore the last backup containing the SMS you want to retrieve. To find out the date of the last backup available for your device:
For iPhone, go to Settings > Your Name > iCloud > Manage Storage > Backups, or your can check your iTunes backup.
For Android, go to Google Drive > Backup.
You must factory reset your device to be able to restore your backup. Then, once you're configuring your mobile phone, you can choose to restore your backup.
By restoring your backup, keep in mind that all your personal data created after the backup will be permanently lost.