Our phones are designed to work in both portrait and landscape orientation – but sometimes, the sensors get too sensitive and end up flipping between viewing more than you'd like.
As of Android 9, there's an easy answer: On a Pixel phone or any device that the manufacturer hasn't interfered much with in Android , go to the Display section in system settings, tap "Advanced," then flip the toggle next to "Automatically rotate screen" in Off mode. From there on, any time you rotate your device, it will not automatically change the screen orientation and will instead place a small icon in the corner of the screen. You can then click this icon to change the rotation or ignore it to leave it as is.
If you're using a Samsung phone, it is strange that the feature is not in your system settings, but you can find the key switch in the Quick Settings area that appear when you scroll down twice from the top of your phone. Find the icon called "auto-rotate" and tap it once to disable it (which will confusingly change its title to "vertical" - but that will do the trick).
555555555