Admit, this is quite annoying: you're turning your iPhone slightly and the screen orientation flips. This makes you lose the place in what you were doing.
It can happen especially often if you're using your iPhone while lying down.
To stop the screen rotation just follow these steps:
Swipe up from the bottom of the screen to open Control Center (or swiping down from the top right on iPhone X and newer).
Tap the Screen Rotation Lock button for the second time, so that the white or red highlight disappears. At the top of the screen you will see a message about the rotation lock status.
By clicking the home button or swiping down the Control Center (or swiping up, on iPhone X and later).