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".

By default, Messages is set to hold SMS text messages and imessages forever. Click "30 Days" or "1 Year" depending on time you want to keep your old messages.

After pressing "30 Days" or "1 Year", a pop-up will appear dialog box that will ask you if you want to delete all messages older than the time period you selected. If you are sure, click "Delete".
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