What is the source of the Magen Dovid (Star of David) in Rabbinic Judaism?
When was it first used, and for what?
The Star of David has been in use as a symbol of Judaism since the 17th century, with precedents in the 14th to 16th centuries in Central Europe, where the Shield of David was partly used in conjunction with the Seal of Solomon (the hexagram) on Jewish flags. Its use probably derives from medieval (11th to 13th century) Jewish protective amulets.
A Shield of David has been noted on a Jewish tombstone in Taranto, Apulia in Southern Italy, which may date as early as the third century CE. The Jews of Apulia were noted for their scholarship in Kabbalah, which has been connected to the use of the Star of David. Medieval Kabbalistic works show hexagrams among the tables of segulot, but without identifying them as "Shield of David".
Gershom Scholem has an essay entitled "The Star of David: History of a Symbol", in The Messianic Idea in Judaism (New York: Schocken Books, 1995), 257-281. In this essay, he chronicles the development of different theories that accounted for its origin (in David's shield, in Solomon's signet ring, etc), its usage in Christian and Islamic art and its frequent appearance (even in Jewish art) alongside either the Hindu swastika or the pentagram.
So far as its actual origins are concerned, it first appears about 600 BCE on the seal of a certain Yehoshua ben Asaiah, and is not again attested until the 2nd or 3rd century CE, when it appears alongside a swastika in a synagogue in Capernaum. There is a flourishing of usage in the Middle Ages, though particularly in what Scholem terms "magical" texts - texts like Sefer Raziel, from which the previous contributor added a picture.
Subsequent to its magical development was its kabbalistic development (a distinction that I am not clear about, but which Scholem does explain elsewhere), though this appears to have been something that came about after the 16th century and that was subsequently retrojected onto the writings of the Arizal - particularly in terms of reconfiguring his layout of the Seder Plate, erev Pesach.
The real flourishing in the use of this symbol is architectural, and Scholem mentions examples of its usage on gates, in windows and as part of synagogue (and church!) adornments. He concludes by noting its being adopted by the Zionists at such a time as it was beginning to be entirely divested of any real meaning, but then closes on a more chilling note:
But far more than the Zionists have done to provide the Shield of David with the sanctity of a genuine symbol has been done by those who made it for millions into a mark of shame and degradation. The yellow Jewish star, as a sign of exclusion and ultimately of annihilation, has accompanied the Jews on their path of humiliation and horror, of battle and heroic resistance. Under this sign they were murdered; under this sign they came to Israel. If there is a fertile soil of historical experience from which symbols draw their meaning, it would seem to be given here.
-Scholem, "The Star of David", 281.
R' Moshe Feinstein wrote in Igros Moshe (O"Ch 3:15) that:
... for hundreds of years the Paroches had Mag Davids drawn on them and no one complained. Even though we have no source of the Magen Dovid, there is no concern [to draw a Magen Dovid on a Paroches (the original question is whether it is a Zionist/Kefira symblo)]. It also reminds us that Hashem rules over us from above, below and all four directions.
What it has to do with Dovid isn't known, but a possibility is to remind [us] of Dovid [Hamelech] who relied on Hashem (who rules from above, below from all four directions) in his battles which is why he wasn't scared of human enemies.
One of my (non-Jewish) childhood friends was interested in magic and the Kabbalah. I remember reading in a book of his that the normal and inverted triangles in the Shield of David represent elemental Fire and Water, and that their combination in the symbol represented peace between opposing forces. (Brings to mind עוֹשֶׂה שָׁלוֹם בִּמְרוֹמָיו...)
I mention this merely as a cute idea I have encountered, and give it minimal credence.