Same principle as a gyroscope: a turning wheel will tend to stay perpendicular or parallel to the direction of the gravity vector because if it starts tilting away from such orientation there’s a force that pushes it back.
Also works better with bigger wheels (if I remember it correctly the effect is related to spinning momentum).
I was pretty surprised when learning Physics and they show us how to derive the formula for that (which I totally forgot since that was over 3 decades ago).
Edit: Actually the gyroscopic effetc is just a part of it. See this article
Actually, it’s the bike’s geometry rather than a gyroscopic effect. Try rolling a bike backwards rather than forward - it’ll topple quickly
Yeah, you’re mostly right: Why bycicles stay upright.
There’s some gyroscopic effect, but per that article it’s not the main reason.
Freestyle BMX riders go in reverse all the time and they don’t fall over.