The Shulchan Aruch (2:6) rules that walking four amos with an uncovered head is forbidden. This is the source for the yarmulka (an acronym of the words yurei malka- fear the king) or kippah. However, why do all males above the age of three wear one?
1. A sign of respect. The Gemarah in Kiddushin (33a) tells the story of a man who walked by Ravina without a yarmulka. Ravina said the Rabbi he was with that the man was brave for not covering his hair. Aruch HaShulchan (2:10) also states that it's brazen not to cover one's head.
2. Fear of heaven. Gemarah in Shabbos (156b) recounts that astrologers told the mother of R' Nachman Bar Yitzchok, "Your son will be a thief." She forbade him from uncovering his head so that he had a fear of heaven.
3. Modesty. In Hilchos Deos (5:6), the Rambam says that Torah scholars are extra modest because they don't uncover their heads or bodies.
4. Chukos Akum. Taz (8:3) says it's a violation of chunks akum, following the ways of the non-Jews, not to cover one's head.
5. Lightheadedness. Taz (61:1) states that one must cover one's head to avoid feeling lightheaded and to not feel that one has no responsibility in this world.