The slightest touch on the edge of the screen while holding the iPhone in your palm may trigger this.
Go to Settings > Accessibility > Touch, then tap Haptic Touch or 3D & Haptic Touch. Choose the touch duration—Fast or Slow. On an iPhone with 3D Touch, you can choose the pressure needed—Light, Medium, or Firm.
Adjust how iPhone responds to your touch - Apple Support (IN)

There are two steps to do that.
- Check your iPhone display before you put it aside or in the pocket. iPhone display will turn off only after your Auto-Lock time settings.
- If the display is ON, lock the screen using the side button and check your iPhone display before you put it in the pocket
Sleep
On iPhone 6 and later, and on iPhone SE (2nd generation) and later, press the side button to wake your iPhone or put it to sleep. Press the top button on the iPhone SE (1st generation) and earlier.
Learn about the buttons and switches on your iPhone.