When viewed from the rear a bicycle looks like an inverted pendulum. Where the wheels touch the ground, it has an effective hinge point. So, if a bike tips a little, gravity acting on the center of mass tends to tip it more. So, superficially, a bike is unstable. Yet in practice, moving bicycles don’t fall over. Why not? This question has three variants. How do bike riders control control bikes to stay up? That is, what forces are invoked to keep the bike from falling? Second, how do people balance bikes when riding no hands? And third, how does ghost riding work? That is, at least some bikes won’t fall over when they are moving fast enough, even with no rider. How does that happen?
The third question, about ghost riding (bicycle self stability), being purely a question of mechanics, seems simplest. In the folk lore, there are two dominant theories: the gyroscopic theory of Klein and Sommerfeld (~1911) and the Castor (aka ‘trail’) theory of Jones (1970). By means of examples, we now know that both were wrong. Gyroscopic terms and ‘positive’ castor are neither necessary nor sufficient, separately or in combination, for bicycle self-stability.
As for what riders do, hands on or hands off, the centrifugal theory of bicycle balance is pretty complete: when having an undesirable fall to the right, you should steer to the right.