This article explains how to turn off message previews on iPhones. Instructions apply to devices running iOS 11 and later.
iPhone 12/12 Pro: How to Show/Hide Text Messages on Lock Screen
When you receive text messages, your iPhone will display a pop-up with the sender's name and the beginning of the message. If you're concerned about your privacy or are waiting for a confidential text message, change this default behavior so that others can't see the contents of your messages. There are two ways to do this: turn off message previews or stop notifications from the Messages app from appearing on your lock screen.
To change your lock screen settings so that message previews are enabled but text notifications don't appear on the lock screen, follow these steps:
Open the Settings app.