The Gemara (Pesachim 6b) proves that on occasion the events in the Torah do not follow chronological order. This principle takes centre stage in a debate amongst the commentaries as to the order of the latter half of Chumash Shemot.
The first half of Chumash Shemot poses no chronological quandaries: parashiyot Shemot until Mishpatim are basically in order: slavery, the plagues, the Exodus, and the Giving of the Torah. However, the next few parashiyot are not so simple. Terumah and Tetzaveh contain the instructions to build the Mishkan and its vessels, as does the first half of Ki Tissa. However, the second part of Ki Tissa speaks about the sin of the golden calf, before Vayakhel and Pekudei return to the building of the Mishkan. What is the correct chronological order of these parashiyot – did the Mishkan come before the sin of the calf or not?
The Ramban writes that these parashiyot are to be ordered exactly as they are written. Hashem gave the order to build the Mishkan in Terumah and Tetzaveh, then the Jewish People sinned with the calf in Ki Tissa. After gaining atonement for this, the construction of the Mishkan was completed in Vayakhel and Pekudei. However, Rashi disagrees. Rashi writes that the command to build the Mishkan was not given until after the sin of the golden calf, which radically alters the sequence of the parashiyos. Indeed, Rashi’s comments on Shir Hashirim (1:11) imply that the Mishkan atoned for the golden calf.
This is part of a broader general debate between Rashi and the Ramban. The Ramban (Vayikra 16:1) writes that unless there is explicit textual proof otherwise (which only occurs once), we assume that the Torah follows chronological order. Rashi disagrees with this, often changing the order when logic dictates so. Perhaps we can deepen our understanding of this debate.
Why did Hashem not write the Torah in chronological order? There are two early approaches to this question.
Rav Yosef Engel (d. 1920) cites a fascinating Midrash. Had Hashem written the Torah in chronological order then potential altercations might have occurred in Shul, because the fellow who was called up for chamishi (the 5th portion) might become jealous of the fellow who got revii (the 4th). Therefore, Hashem deliberately made the order of the Torah hazy; now nobody will be able to claim that another’s call-up was less important as it occurred earlier – since perhaps it was detailing an event that actually occurred later, chronologically speaking. Whilst this reason may fit with Rashi’s view, it certainly does not fit with the Ramban’s view, since the Ramban’s necessary textual proof to change chronological order would not make the order hazy enough to assuage arguments.
A differing Midrash suggests kabbalistically that had the Torah been written in chronological order then anyone would have been able to manipulate the mystical secrets of the letters of the Torah (which were used in the creation of the world) to fashion new creations. Therefore, Hashem concealed the Torah’s order to prevent such tyranny. This would seem to fit the Ramban’s view.
A take-home message? Preservation of peace is critical, especially in our Shuls. Note that Rashi has the end of Mishpatim occur before Matan Torah  Ramban, Shemot 33:7  Rashi, start of parashat Terumah and 33:7  Quoted in Tosafos Rabbeinu Peretz Pesachim 6b. It is Midrash Tanchuma Terumah 8. The Nefesh Hachaim 4:28 cites a similar midrash Tehillim (Shocher Tov) 3, and explains this concept somewhat.  Pesachim 6b