Connect the affected phone to a computer, and download a recovery tool such as Wondershare Dr. Fone for Android or iPhone, or Android Data Recovery. Follow the directions specific to the software and the operating system for your phone.
For Wondershare Dr. Fone for Android, go to the Settings menu, and choose Developer Options. To get access to these, go to About Phone, scroll to Build Number and tap the screen repeatedly. Developer Options appears just over About Phone. Enter Developer Options, and scroll to USB or Android Debugging, then check the box.
Use a USB cable to connect the phone to your computer after you install the recovery program on the computer, and start it up. Follow the steps in the wizard to analyze the memory of your Android phone. Look through the data to find the text message folder, then look at the messages, and use the Recover feature in the software to return them to your phone. Alternatively, save them to your computer for permanent storage.
If you don't have a PC to use a recovery program, you likely need root access on your phone and, in most cases, a paid recovery app. Using a computer is simpler and costs nothing.