As per the article https://support.apple.com/en-in/guide/messages/icht1035/mac
Delete a conversation:Â Select a conversation, then choose File > Delete Conversation. Or, if you have a trackpad or a Magic Mouse, you can also swipe left with two fingers on the conversation in the sidebar, then click Delete.
If you use Messages in iCloud, deleting a conversation on your Mac deletes it from all your devices where Messages in iCloud is turned on.
So check out the messages box is turned as on in an iPhone see the article https://support.apple.com/en-in/guide/iphone/iph3d039b67/ios
Go to Settings  > [your name] > iCloud, then turn on Messages (if it’s not already turned on).
Read this also https://support.apple.com/en-in/HT208532