Upon seeing the nation worshipping the golden calf (Sh’mos 32:19), Moshe shattered the Luchos, the stone tablets that were “G-d’s handiwork, with G-d’s writing engraved into them” (32:16). This “writing” was, at the very least, the “Ten Commandments,” the directives G-d spoke during His public revelation on Mt. Sinai (see D’varim 4:13 and Rashi on Sh’mos 24:12), an event that had occurred a mere 41 days prior to this incident (from the 6th or 7th of Nisan until the 17th of Tamuz). Since the nation started worshipping the golden calf early in the morning of the 17th (Sh’mos 32:6), and Moshe didn’t descend until hours later (see Rashi on 32:1), how could G-d give Moshe the Luchos at all? G-d approved of Moshe breaking them (see Shabbos 87a), so why give them to him in the first place?
Chizkuni (Sh’mos 31:18) says that G-d gave Moshe the Luchos “at the end of the 16th of Tamuz” (these are his words as they appear in the manuscript; many printed editions say “as morning broke on the 17th” instead). If so, G-d gave Moshe the Luchos before the sinning had started (even if He gave them to Moshe “as morning broke,” it was still before they sinned); for all we know G-d would not have given him the Luchos had the nation already begun to worship the golden calf. [Even though the golden calf was formed the day before (32:4-6), Aharon’s intentions were pure (see Rashi on 32:5), and it was only the “Eiruv Rav” who sinned on the 16th (see Rashi on 32:4); the Children of Israel didn’t sin until early on the 17th.] The Torah does tell us that G-d gave Moshe the Luchos before it tells us about the golden calf, indicating that they were given to him before the sinning began.
Aside from side-stepping the issue of G-d giving Moshe the Luchos after the nation had already sinned, Chizkuni’s approach helps address another issue as well. The Torah says that Moshe “was late coming down from the mountain” (32:1), which is understood to mean that there was a miscommunication between Moshe and the people about when he would return (see Rashi). However, if Moshe wasn’t really late (rather, they thought he was late), why does the Torah phrase it as if Moshe really was late? Based on Chizkuni’s approach, we can understand why the Torah says that Moshe tarried before he came back down; G-d didn’t give Moshe the Luchos until He had “finished speaking with him” (31:18), so there was no imperative for Moshe to stay atop Mt. Sinai any longer. He may have wanted to, in order to extend the unique spiritual experience for as long as possible, but he didn’t have to. (Much can be inserted here about the balance between the need for a leader to forgo personal benefit in order to be fully devoted to the community and the need for a leader to continue his or her personal growth in order to be able to better serve the community.) After daybreak, Moshe could have descended Mt. Sinai, with the Luchos, and returned to the nation in time to prevent the tragedy of the golden calf. Instead, because he “tarried,” the sinning began before he got there. Although the “tarrying” is mentioned on the 16th, which was before Moshe was given the Luchos and before his work atop Mt. Sinai was done (so the misunderstanding about when he would return allowed the process of making the golden calf to begin), because he actually did “tarry” on the 17th, the Torah says “he tarried” rather than “the people thought he had tarried.” [This explanation is supported by the wording of Midrash Tehillim (18:13) which says “when Moshe went up on high and remained there and Israel made the calf.” There is no reason to include “and remained there” if his staying longer than necessary was not a contributing factor.]
Many Midrashim connect the word “as He finished,” (Sh’mos 31:18) which has the root letters of kaf-lamed-hey, with the Hebrew word for “bride,” which has the same letters (likely because that is when she is considered “complete,” an inverted version of the old joke that a man is not complete until he’s married; then he’s finished), comparing the giving of the Luchos to things that occur when a bride gets married. Midrash HaGadol compares it to a king who was getting engaged to a woman, but was afraid to give her an engagement ring (or whatever jewelry would have been expected at an engagement) in case she denied that they were ever engaged, yet kept the jewelry. At the same time, the king didn’t want to hold on to the gift lest she accuse him of promising to give her jewelry without really intending to give it to her. To avoid this, the king gave the jewelry to a third party, so that she knew that he did intend on giving it to her, without risking her keeping it and not going through with the marriage. Similarly, Moshe was the “third party” when he received the Luchos, indicating that they were not yet being given to the nation. If Moshe was given the Luchos to indicate that G-d was willing to give them to us, but not until they committed to only worshipping the One True G-d, it would not be problematic that He gave them to Moshe even after the sin of the golden calf (since the “gift” was contingent on a subsequent recommitment to G-d).
The commentators on Rashi discuss why he insists (31:18) that the commandment to build the Mishkan couldn’t have come before the sin of the golden calf (in some editions of Rashi, the publisher asks this question without suggesting an answer; I am also puzzled by it, and haven’t found a satisfactory answer). In his expansion of Mizrachi’s approach, B’er Yitzchok differentiates between G-d commanding the Mishkan despite knowing that the nation would sin (which Mizrachi says He wouldn’t do since He would have to repeat the commandment anyway after they repented; I don’t understand why this is different from teaching Moshe the rest of the Torah, or why He couldn’t just say “the Mishkan is back on” after they repented without having to repeat every detail) and giving Moshe the Luchos despite knowing they would sin. Although neither (Mizrachi or B’er Yitzchok) see any reason for G-d to teach Moshe about the Mishkan if it wasn’t relevant until after Moshe achieves forgiveness for them, B’er Yitzchok adds that G-d gave Moshe the Luchos so that he would break them, thereby demonstrating to the nation how serious their offense was, which was instrumental in their repentance. If this was enough of a reason to give Moshe the Luchos despite knowing that they were about to worship the golden calf, it would also be enough of a reason to give them after the sinning had started. Nevertheless, it would seem that there is a more fundamental reason why G-d gave Moshe the Luchos despite either knowing that the nation would sin or despite their having already started to.
Before Moshe descended Mt. Sinai with the Luchos, G-d had already retracted his threat to wipe out the nation (32:14-15). [It should be noted that according to Chizkuni (32:11), based on Ibn Ezra (ibid) and possibly the Midrash quoted by Yalkut Shimoni (744, source 18), Moshe’s prayer on behalf of the nation (32:11-13) and G-d’s response to it (32:14) didn’t occur until after Moshe had descended from Mt. Sinai and started working on repairing the damage. (Chizkuni paraphrases Ibn Ezra’s argument by asking how Moshe could consider asking G-d to forgive them if they were still sinning.) This fits with Chizkuni saying that Moshe was given the Luchos before the sinning had ever started, as there was no “forgiveness” before Moshe descended. Most sources, however, are of the opinion that G-d retracted his initial threat before Moshe descended on the 17th of Tamuz, which fits better with Moshe’s prayer being split into two (part before he descended and part after).] The wording of the verse is that He retracted “the evil that He spoke of doing to His nation.” Yes, they were still considered “His nation,” even before Moshe was able to halt their sinning and start the process of repentance. In his prayer, Moshe referenced the promises G-d made to our forefathers about their descendants being heirs to their spiritual legacy. It would be impossible for this to occur (or for them to be “G-d’s nation”) without the Torah, so once there was even a partial retraction (i.e. not destroying them, see Ramban on 32:11), the Torah had to be given to them. (This is similar to Mizrachi’s explanation as to why G-d would give us the Luchos even if there wouldn’t be a Mishkan.) Since ultimately we need the Torah in order to fulfill our mission as His nation, G-d gave Moshe the Luchos despite the sinning that was still going on.