Request for links for the rest of the sources, if you can. The Midrash Tanchuma is clearly not talking about haircuts, though! It's just talking about normal human development, that kids don't communicate so well until they're three.
– JXGJun 14 '11 at 7:06

@JXG. I added some more sources to the answer. I wasn't quite sure what the proof was from the Midrash Tanchuma either. Check out the Nitei Gavriel I linked too as well, he brings it all, and more.
– MenachemJun 14 '11 at 21:08

However, one thing not mentioned is that the practice has a German name, upsheren, and furthermore that:

The Pennsylvania German superstition prescribes a wait of a year before the first haircut, lest the infant lose its hair, be a weakling, or die young: EM Fogel, op. cit. (see note 24), 42, nos. 81-82; 43, no. 83

(From Conception, birth and infancy in ancient Rome and modern Italy, by Walton Brooks McDaniel.)

It is fairly easy for a superstitious practice adopted from the general culture to accumulate religious ex-post-facto rationalizations.

(Yes, I am aware that one year is different from three years. But superstitions change over time and manifest differently.)

I find it hard to believe that a Pennsylvania Dutch practice worked its way into such a broad swath of Jews' practice.
– msh210♦Jan 10 '12 at 18:53

2

Me too. However, an Old German superstition could work its way into Germanic Jewish custom, as well as working its way into the superstitions of the Dutch that eventually moved to Pennsylvania. In other words, not that A got from B, but that A and B got from C.
– josh waxmanJan 10 '12 at 19:35

2

I read that this is attributed to a pagan initiation practice in the Gemara and was instituted for the first time in Judaism by the Ari, which would better explain the prevalence in Kabbalistic circles a/o to German ones. IIRC German Jews don't do Upshearing.
– Yaakov KupermanMar 30 '12 at 3:39

1

interesting. i haven't researched this sufficiently. rav chaim vital "describes how the Arizal went to the village of Miron on Lag B'Omer and participated in the “known Minhag” of upsherin." so it might have already been a known practice in his days.
– josh waxmanMar 30 '12 at 3:55

1

The name of the Upsherin is unrelated to its origins, e.g. some claim that it was started as a result of influence by Muslims who cut their children's hair at sanctified gravesites, and later was brought to Ashkenazi Europe in the Middle Ages (to this day it is known among many Israelis as 'halaka', Arabic for 'shave'). At that time Ashkenazi Jews may have adopted a local name for it.
– ChaimKutMar 30 '12 at 14:19

Aside from the previously mentioned ideas, Wikipedia suggests it might have developed from an older custom to bring children to the grave of Samuel the Prophet (שמואל הנביא) north of Jerusalem and cut their hair there. After the Ottomans restricted Jews' access to the site in the 1500's, it was later moved to Meron, near Tzfat.

The connection to Samuel is probably related to the story of Samuel I 1 where Samuel was kept to the family until he was weaned, and only then brought to the Temple in Jerusalem and sanctified to the service.

I recently heard a reason: that it was originally a superstition to fool the Satan. I.e. the Satan wants baby boys, so by leaving them with long hair, the Satan is fooled until they are no longer of interest.

This would fit with a reason given from YWN Coffee Room referenced in another answer:

A very significant consideration is also the question if there is a
problem of 'chukos hagoyim' with the custom. While we don't generally
see it now (in western countries at least), the fact is that in certain
eastern cultures (e.g. arab and hindu / Indian) a great deal was/is
made of a son's first haircut and it was accompanied by a significant
celebration. It seems that those Jews who started the custom Jews
lived among such gentiles. So there is a concern that it may well have
originated in gentile practice. ....

This would also fit with the idea of it being a German folk superstition.

There appears to really be three different, possibly interconnected, issues here.

Celebrating the first haircut.

Cutting hair by kivrei tzadikkim, especially Rashbi and Shmuel.

The age of the haircut.

It would be useful to carefully indicate which sources address which issues. Looking at some of the sources mentioned in the previous posts, most of the earlier sources discuss going to graves of shmuel/rashbi and some mention celebrating. The idea of three years of age does not begin to appear until later, according to netai gavriel, originating in chassidic circles (from the baal shem tov).

It would then appear that these three aspects should be analyzed independently.

In terms of the celebratory aspect, the netai gavriel, as mentioned above, links this with the mitzvah of peyus. To say it more precisely, this is the first time the peyus are specifically not cut - it is an active fulfillment of the prohibition not to cut peyus! This can be taken in two directions.
1) The people cutting the hair are fulfilling, so to speak, the mitzvah not to cut the peyos.
2) There is chinuch for the child, teaching him not to cut peyus (and essentially highlighting the uniqueness and singularity of the Jewish people). The celebration is then, in some sense, a seudas mitzvah (although, I emphasize again, unique since we are dealing with a negative commandment).

What about three years of age? This is a later and less universal aspect of this first haircutting, and as always we can only speculate as to what those who originated the practice were thinking (i.e. why they thought it would be a proper thing to do). It is very possible, as it has more chassidish origins that the notion is deeply steeped in kaballah, which is why the average person really doesn't know. However, I was thinking to suggest something simple. As some of the sources in chazal already mentioned above indicate, there is an element of maturity and chinuch which begins at three. Hence, independent of all this hair cutting business there is the notion of wearing tzitzis, yarmulke, and learning torah upon turning three. If that is the case, then for the chinuch of peyos, what better age than three!
Of course all of this is just a speculation. I also haven't added much which hasn't been said or mentioned in sources which are referred to already, but I felt the discussion needed some organization and structuring. I am still left wondering what the rashbi/shmuel and lag ba'omer have to do with a haircut? Anyone have explanations of this?

Before I finish this post, I would like to mention two more things.

1) One must be cautious when suggesting that the origin of a practice is borrowed from another culture. Parallelism does not imply borrowing, and in some cases, who is to say who got it from whom. One must recognize that it is a speculation. It is no more certain than any other reason which is suggested. In fact, it requires one to believe that a group of Jews who were not too religious (i.e. they would copy from the practices of idolators) or who became overly enticed by eastern Hindi religious practices started to celebrate haircutting, and copied muslims who would cut hair at grave sites. Eventually this idea spread to other people, who did not realize where it came from or understand what it was about, eventually to truly righteous people, and then to the entire Jewish world. Can one say that this is impossible. No. But how likely does that really seem? Of course, in the academic world, the idea of being influenced by another (idolatrous!) culture will be popular, and stated as if certain. However, this is due to bias rather than evidence and reason. Sorry for the rant, but this is an all too common problem. More honesty and accountability is needed here.

2) It is interesting to think about the notion of evolving minhagim. Every minhag must have a start, and minhagim often have many details added to them over time. And they always begin small, and eventually spread. One can always ask: why should a minhag ever start and spread? Were the people before the invention of this minhag doing something wrong by not doing it? After all, there is a reason behind the minhag, so why weren't earlier generations cognizant of this reason? Going out on a limb, maybe this gets at the notion of the spiritual evolution of the world. Precisely, at certain times in history, the world progresses spiritually, and it becomes the right setting for the introduction and spreading of new minhagim. Taken in this light, minhagim, even if recent, represent the spiritual progress of the world. This would very much change one's attitude toward upsherins. Are certain elements and its universality of contemporary origin: yes. But does this negate its value: no. Maybe it only highlights the progression of the world toward the ultimate ideal. Just a thought.

Two disparate hair-related practices appear to have converged in the haircutting ritual: the growing of ear-locks payoth - s.d.] and the shearing of the head hair. ... Ritual haircut, probably modeled on the Muslim custom of shaving male children's hair in saints' sanctuaries, was practiced by native Palestinian Jews (Musta'arbim) as early as the Middle Ages. Rabbi Isaac Luria Ashkenazi, the 16th-century founder of the celebrated Lurianic School of Kabbalah who assigned special mystical value to the ear-locks, was instrumental in constituting the ritual in its present form. The ritual remained primarily a Sephardi custom following Luria, but in the last 200 years it became widespread among East European Hasidim. From Palestine it spread to the Diaspora communities, where it was usually celebrated in a more modest family setting.