AIUI, the Cliff’s Notes version of the current theory of how the mythical/historical parts of the Bible were written, which I’ve seen called “the supplementary hypothesis”, goes something like this;
- Before the fall of Samaria in 720 BC, the northern and southern kingdoms had distinct traditions of their history and religion. The southern tribes called their god Yahweh and believed he was incorporeal but metaphysically present in Jerusalem and had a priesthood that claimed descent from Moses. The northern tribes called their god El and worshipped him as a golden bull, with temples in Bethel and Dan, and a priesthood claiming descent from Aaron. Both groups also associated their god with mountaintops and had secondary temples in “high places” throughout the kingdoms. The Holiness Code, which would later become part of the P source, develops gradually over several centuries during this time. Several of the “poems” that appear in the Torah, such as the song of Miriam, the song of Deborah, and Moses’ speech in Deuteronomy 32, also date from this era.
- After the fall of Samaria, the northern Israelites who were not taken as slaves and refused to assimilate into Assyrian culture fled south, where tribal identities became muddied and lost due to intermarriage and the tribes no longer living in distinct territories. The two traditions begin to intermingle at this time but there is conflict over whose version is right.
- During the reign of King Josiah, a member of the Mushite priesthood who we call the Deuteronomist (speculated to have been the prophet Jeremiah) composed most of the book of Deuteronomy as an argument for the supremacy of the Mushite/Yahwist POV, and presented it to Josiah as being a lost document from the days of Moses that had been found in a storeroom in the Temple. Based on this document, Josiah enacted a wide-ranging religious reform, ordering the high places destroyed and centering all religious practice at the temple in Jerusalem, and in particular enacting a ban on idolatry aimed at the bull cult of El. The story about Aaron, the progenitor of the northern priesthood, being the creator of the golden calf originates around this time.
- Around the same time, the Deuteronomist composes a hagiographic history of the Israelites from the death of Moses to the present day, which emphasizes Josiah as being the rightful successor to Moses and David and the fulfillment of prophecy. This history becomes the books of Joshua, Judges, Samuel, and Kings. This same author also writes the book of Jeremiah.
- After the fall of Judah and the beginning of the Babylonian exile, a second author writes an addendum to Kings which details the reigns of the last few kings and the fall of the kingdom.
- During the period between the fall of Samaria and the end of the exile, the traditions of the northern and southern kingdoms begin to coalesce into a single narrative, which comprises the J and E sections of the Torah.
- After Persia conquers Babylon and Cyrus grants home rule to the Jews, Ezra and Nehemiah are charged with reconstructing the priesthood, overseeing the rebuilding of the Temple, and standardizing Jewish religion and practice. The reconstituted priesthood follows the legacy of the southern Mushite priesthood, but now claims Aaronic descent instead. The P source is written at this time to codify the laws and establish an official version of ancient history and the life of Moses, incorporating the Holiness Code, while J+E continues to evolve as folk tradition.
- At some point in the subsequent two centuries, J+E is combined with P to create the books of Genesis, Exodus, Leviticus, and Numbers. Deuteronomy is then appended to the end of this text with a few addendums to tie it into the narrative.
- By the beginning of the rabbinic era, the history of how these texts coalesced into a single document is forgotten, and it becomes an article of faith that the whole of the Torah was written by Moses, including the parts about his future and his own death, as dictated to him by God during the theophany on Mt. Sinai.