Hashem tells us in the Torah that we should sit in the Sukkah for seven days; “BaSukkot Teishevu Shiv’at Yamim” (VaYikra 23:42). Seemingly, the reason for the Mitzvah is that Hashem houses Bnei Yisrael in Sukkot when they leave Egypt, and further generations should know this, as the Pasuk states (VaYikra 23:43), “Lema’an Yeide’u Doroteichem Ki BaSukkot Hoshavti Et Bnei Yisrael BeHotzi’i Otam MeiEretz Mitzrayim.”
However, regarding the actual recording of Yetziat Mitzrayim, the Torah doesn’t mention the fact that Hashem houses Bnei Yisrael in Sukkot. Instead, the Torah states that Hashem protects them with the Anan, the heavenly cloud, which leads and protects Bnei Yisrael during the day, and the fire at night which serves the same purpose. The Torah emphasizes greatly how protected Bnei Yisrael are because of the Anan when it describes the story of the Egyptians chasing Bnei Yisrael and shooting arrows at them. Incredibly, the Anan blocks the arrows from reaching Bnei Yisrael, thereby saving them (see Rashi to Shemot 14:19) However, while the Torah emphasizes what Hashem does in order to save us, it does not even make mention of Hashem using Sukkot to shield Bnei Yisrael. If so, to what does the Pasuk refer when it says that our Sukkot are meant to teach us, the later generations, that Hashem shielded Bnei Yisrael in Sukkot as he took them out of Egypt? What Sukkot?!
One possible answer, as Rabi Eliezer and Rabi Akiva contend, is that the Torah is teaching us through this Pasuk (quoted above, VaYikra 23:43) that Hashem does shelter us in Sukkot as he takes us out of Egypt. In the Gemara (Sukkah 11b), Rabi Akiva believes that this Pasuk refers literally to Sukkot, and Rabi Eliezer believes that the Pasuk refers to the Ananei HaKavod with which Hashem protected us.
However, I would like to suggest a different answer that gives an insight into the nature of the Mitzvah of Sukkah.
In Masechet Sukkah (2a), Rava argues that the commandment of Sukkah is to go from your permanent settlement into a temporary settlement. Rava focuses on the fact that the Sukkah is supposed to be an impermanent abode, which shows that the function of the Mitzvah is to live in a temporary settlement.
The Sukkah is obviously not the most protective building that one can imagine. It is vulnerable to rain and to wind, and therefore one must rely on Hashem for protection in the Sukkah. More importantly, the Sukkah represents equality. During the rest of the year, people are separated by the types and sizes of their homes, as well as by their cars and all of their monetary goods. But for about seven days out of the year, Hashem commands us all to go into a small and unsafe building and rely on Him for safety and for comfort. The Sukkah has the effect of unifying all Jews and putting us into the same situation throughout Sukkot, as we live with the same level of non-luxury for the entire time.
In this sense, the Sukkah teaches the affluent not to be too confident, as their protection comes from Hashem. It also teaches the poor to remember that Hashem is protecting them, even if they lack in material possessions.
Now we can explain the Pasuk that states that Hashem shelters Bnei Yisrael in Sukkot as he takes them out of Egypt. It is speaking not in a literal sense, but in a more metaphorical sense. Hashem protects Bnei Yisrael by creating a situation of equality in the Midbar in order to show them that He is in control and that they don’t need to be more successful than others are. Hashem accomplishes this through the Man, which forces everyone in the nation to eat the same food. Additionally, the camp is configured in a way in which everyone is equidistant from the Mishkan, again creating a sense of equality.
The Sukkah as well is supposed to remind us of how Hashem creates this sense of equality. It influences us to recognize that in reality, we are really all equal. For seven days we move to our Sukkot and remember that Hashem is really in charge and that He is the one sheltering us.