Initially, it was assumed to be due to the gyroscopic effect - but that was very popularly debunked by David E Jones by constructing a bicycle with an extra wheel to spin in the opposite direction, hence negating the angular momentum generated by the primary wheel. This cycle was demonstrably ride-able hence disproving that gyroscopic stability was the primary reason for cycle balance. Afterwards, the castor effect became pretty popular until this group found that they can still construct a self-balancing bicycle without the above two effects being prominent. This research was conducted in 2011 (TED talk by same people) and I couldn't find any other solid research done on this topic which leads me to think this is still a largely unsolved problem in dynamics.
I understand there might not be a single simple answer to this, so any further reading for the same is appreciated.