How to hide message details on the lockscreen?

Go to Settings > Display > Lockscreen > Privacy to pick the notification preview option.