By default, your iPhone and iPad store every iMessage text message and SMS you receive. As a result, you could store your messages in iCloud which will take up valuable space. Fortunately, there is a way to automatically delete old text messages. See how.
First, open "Settings" on your iPhone or iPad.
In "Settings", click on "Messages".
In the "Messages" section, scroll down and click "Keep Messages".
Warning: After you press Delete, your iPhone will automatically delete all text messages that are older than 1 year or 30 days, whatever choose. You will not be able to restore them.
After that, exit Settings. From now on, Messages will automatically delete any messages as soon as they reach 30 days or 1 year, depending on the option you have selected.
Source of information: howtogeek.com