After writing about the mitzvot and Moses' presence on Har Sinai, the Torah abruptly jumps to the commandment of building the Mishkan. Why is this commandment here, in the middle of the story of Moses' ascent to Har Sinai? The answer to this question lies in the purpose of the Mishkan.
Rash"i and the Ramba"n argue about when God commanded to build the Mishkan. Rash"i, (31:18) citing the rule of Ein Mukdam UMeuchar BaTorah - literally, "there is no strict chronology in the Torah" - concludes that God dictated the building after Cheit HaEgel - the sin of the golden calf. The Ramba"n (35:1), on the other hand, maintains that the Torah was written in the correct chronological order, and consequently God commanded Moses to build the Mishkan before Cheit HaEgel.
Additionally, Rash"i and the Ramba"n disagree in their explanations of Cheit HaEgel itself. Rash"i (32:1) explains that the nation of Israel "desired many gods." He maintains that Israel's sin was avoda zara- meaning they wanted to serve other gods. The Ramba"n disagrees, stating that Israel did not want the calf as a new god, but rather, they wanted it as a replacement for Moses. They thought Moses had died and therefore they selected a new leader.
According to Rash"i, Israel was unfaithful to God by committing the sin of the golden calf, thereby distancing themselves from Him. The antidote was to become closer to God. The commandment to build the Mishkan served as an atonement for their sin, while also providing a home for the Divine Presence into their encampment.
However, according to the Ramba"n that the imperative was given before the sin, what was the purpose of the Mishkan? If the command to build the Mishkan preceded Cheit HaEgel, the purpose of the Mishkan cannot be coming to atone for this sin! Moreover, Cheit HaEgel was not an act of rebellion by the people requiring a new structure to atone for it. The Ramba"n believes that the Mishkan served to perpetuate Ma'amad Har Sinai - the revelation at Sinai. We see that there are several similarities between Ma'amad Har Sinai and the Mishkan. The Divine Presence was present in both of them through Eish VeAnan - fire and clouds. No one in the nation was allowed to touch Har Sinai, or to enter the Mishkan, even Moses was able to enter only after being called by God. So in contrast to Rash"i, the Ramba"n believes the nation of Israel was at an extremely high level of kedusha - spiritual purity - at the time of the command to build the Mishkan. The Mishkan was not a solution to the Jews' spiritual troubles but an outlet for God's revelation.