Try this if your contacts are in iCloud or in your chosen email account
(You might want to back up the phone first, and if your contacts are phone only you have no remedy)
Close Messages app. then for
Contacts in iCloud:
Settings, Your name, iCloud, Turn off contacts
Contacts in another email account
Settings, Contacts, Accounts
Find the account with Contacts turned on. Turn contacts off
When asked if you want to keep them, choose “delete from my iphone ”
Open Contacts app and it should be empty.
Power the phone off and back on.
Then
Contacts in iCloud:
Settings, Your name, iCloud, Contacts. Turn it On
Contacts in another email account
Settings, Contacts, Accounts
Find the account with the Contacts again. Turn contacts On
Open Contacts app and it should be re-populated.
Then try messages again.
You might find these interesting
About Apple IDs
Sync your contacts
If your contacts do not sync