Messages cannot change the name of contact unless you have tapped on a link sent by your friend to add to contacts etc.
Unlike some Android devices, contacts are neither stored locally on an iPhone nor in SIM. They are synced to an email account that you had Google, iCloud, AOL, Exchange, Outlook, Yahoo or any Other
If Contacts were on iCloud, try this --> Restore contacts, calendars, bookmarks, and more using ...
Else Add the email account that stores your contacts in the IOS mail app and enable Contacts. If you have a corporate email account added through a profile on your device, please check with your organisation's system administrator.