It's due to the steering geometry. If you extend an imaginary line through the pivot axis of the front wheel to the ground the contact patch will behind where this imaginary line intercepts the pavement. For bicycles and motorcycles, it's called trail, for cars it's called caster.
When a bicycle is leaned over, gravitational downforce is applied to the center of the front wheel at the horizontal axis of the front wheel, while a opposing upwards reaction force is applied from the pavement at the contact patch. Since the contact patch is "behind" the pivot axis, this creates a inwards turing torque on the front wheel, and is designed create a corrective steering response that returns the bicycle to a vertcial position as long as the speed is above a crictial minimum speed. The critical minium speed depends on the amount of trail; the longer the trail, the lower the minimum speed.
Trail results in vertical stablity, a tendency towards veritcal orientation. Gyroscopic reaction results in roll stability, a tendency to hold the current lean (roll) angle. As speeds increase, the gyroscopic reaction becomes more significant, and at around 100mph on a motorcycle, the gyroscopic reaction of holding a lean angle is the dominant one and there's virtually no tendency to return to vertical. This consequence of high speed riding experienced by motorcycle racers is that it takes virtually the same amount of counter-steering effort to return to a vertical orienation as it does to lean over.