In this post, I'll write about the Ten Commandments in Exodus 20, according to Raymond Collins in his article on the "Ten Commandments" in the Anchor Bible Dictionary. Collins states the following:
"Each of the biblical versions of the Ten Commandments is postexilic in its present form. Most scholars agree that Exod 20:1-17 interrupts the Exodus narrative (Exod 20:18 relates to the theophany at Sinai and continues Exod 19:25). Thus the present relationship of the Ten Commandments to Sinai is considered to result from relatively late redactional work upon the Exodus narrative."
Why does Collins regard the Ten Commandments as post-exilic? In his comments on the Fifth Commandment ("Honor your father and your mother"), Collins states that "During the postexilic period the commandment was particularly significant because of the importance of society's seniors in passing along the traditions of the people", and he notes that wisdom traditions (Proverbs 1-9 and Sirach 3:1-16) "elaborate on the implications of the commandment." But I am not convinced that this is a sufficient basis to regard the Ten Commandments as post-exilic. I can't really refute it, but I'd like to see a stronger basis than a command which highlights a principle that would be a reasonable precept in all sorts of time periods.
Collins later says that the Ten Commandments are "rarely cited in the Hebrew Bible (Hos 4:1; Jer 7:9)", but Collins does not then argue that this is because the Ten Commandments are late, or post-exilic. So I don't know why Collins regards the Ten Commandments as post-exilic.
As for his claim (and the claim of many scholars) that the Ten Commandments were inserted into the Exodus narrative, that makes sense. The Ten Commandments appear awkward within their context. Exodus 19:25 says that Moses went down to the people and spoke to them, and then Exodus 20:1 has God speaking the Ten Commandments. So Moses went down from the mountain, spoke to the people, and then God interrupted Moses by speaking the Ten Commandments? I can see Collins' point that Exodus 20:18 follows Exodus 19:25 much more smoothly than Exodus 20:1-17 does: Moses goes down and speaks to the people (presumably to keep them from approaching to look at God, which would bring death---see v 21), the people saw the thunder and heard the trumpet blast and wanted Moses rather than God to speak with them, Moses exhorts the people that God is teaching them the fear of God to discourage them from sin, the people stand afar off, and Moses goes into the thick darkness to hear God's commands---which are the Covenant Code.
What are scholarly ideas about the origin of the Decalogue? Collins describes some views. One view is that the Decalogue was based on social morality that was promoted by the eighth century prophets and Jeremiah (who was from the seventh century). Another scholar believed in four redactions of the commandments: the Elohist's in the eighth century (the time of Amos and Hosea), the Yahwist's (from Hezekiah's day), the Deuteronomist's (which is seen in Deuteronomy 5), and the priest's (who expands the Sabbath command in Exodus 20:8-11 and Deuteronomy 5:12-15). But this view appears to hold that the Decalogue had its roots in the northern Elohist tradition.
Sigmund Mowinckel located the Decalogue in the cult, viewing it as an entrance liturgy for worship---of the sort that we encounter in Psalms 15 and 24 (and Psalm 15 has ten moral prerequisites). And Mowinckel could point to appeals to Decalogue precepts in the Psalms---as in Psalm 50:16-20 and 81:9-10.
G.E. Mendenhall thought that the Decalogue was similar to second millennium Hittite vassal treaties, which required that both parties to the agreement receive a tablet---which is what happens in the biblical Decalogue story, only the Israelites receive a copy of the covenant stipulations.
E. Gerstenberger located the Decalogue in clan ethics. And Anthony Phillips said that the Decalogue was a summary of Israel's criminal code, which makes sense to me, since the Pentateuch has commands against idolatry, murder, adultery, dishonoring parents, etc.
I'll probably revisit the issue of the Decalogue, since I need to iron things out some more.