There are two separate issues of covering the head in Judaism, one for men and one for women.
"Nowadays there is a definite prohibition...(not only to walk a short distance, but) even to sit (in the house) bare-headed."
Shulchan Aruch, Orach Chayim, Ch. 8.
"Small children should (also) be brought up to cover their heads."
Shulchan Aruch, Orach Chayim, Ch. 2.
The basic halacha of covering the head for men is that it is forbidden to walk four cubits (about 8 feet or 2.5 meters) with an uncovered head. According to some authorities it is forbidden to go any distance at all without a head covering. It is even considered improper to sit in one's home with an uncovered head.
It is also forbidden to say a prayer with the name of G-d or to study Torah without a head covering.
The Talmud says, that the mother of Rabbi Nachman bar Yitzchak would not allow him to go with his head uncovered for she said, "Cover your head in order that you should have the fear of heaven upon you."
Another basis given for this practice is to avoid the customs of the non-Jews.
It is an explicit law (Shulchan Aruch, Orach Chayim, Ch. 75) - and not only a custom - of the Torah that a married woman is to cover her hair, Kisui HaRosh.
"The priest shall stand the woman before G-d and uncover her hair..."
BaMidbar (Numbers) 5:18
The source for this prohibition is from the above verse, which deals with the laws of a sotah - a suspected adulteress. Rashi provides two explanations in the Talmud, Ketuvot 72a: One, that from the fact that she is punished midah keneged midah (measure for measure) for exposing her hair, we see that this is prohibited. Two, from the fact that we expose her hair we see that under normal conditions a Jewish woman's hair should be covered.
Moreover, from the great reward received for performing this mitzvah one can learn that there is great importance to fulfilling this law.
As the Zohar states (III, 126a) in Parshat Naso, (Mishnah Brurah, Laws of Kriat Shema, Ch. 75): "Her children will enjoy increased stature over other children; moreover, her husband shall be blessed with all blessings, blessings of above and blessings of below, with wealth, with children and grandchildren..."
These blessings and good fortune extend to the husband, wife and the children that G-d will bless them with.