The reason for why G-d commanded us to build a Sukkah: The verse states that we are to dwell in a Sukkah for seven days in order so our future generations remember that G-d settled the Jewish people in Sukkos when he took them out of Egypt. The term Sukkos here refers to the clouds of glory, which surrounded the Jewish people for the sake of giving them shade, so the heat and sun do not injure them. Thus, as a replica of this event, G-d commanded us to [build and then] dwell in a Sukkah that is made for the purpose of providing shade in order so we recall the miracles and wonders [done for us in the desert, in which the clouds of glory surrounded us for shade, and served as a protection from the sun]. Therefore, when dwelling in the Sukkah, every person must have intent to do so in order to fulfill G-d’s command to dwell in the Sukkah in commemoration of the Exodus. See Chapter 3 Halacha 1-2!
 Admur 625:1; Michaber 625:1; Rebbe Eliezer Sukkah 11b; See Piskeiy Teshuvos 625:1
Other opinions: According to Rebbe Akiva [Sukkah ibid] we slept in actual Sukkos, and the reason behind the holiday of Sukkos is to remember all the kindness that Hashem provides us with throughout the year, as in the desert we lived in considerable lack of wealth, not having any land or produce. Thus, in order to remind us of this, and give gratitude to G-d for all that he has provided us with, therefore we sleep outside of our homes in a Sukkah and learn to gain appreciation for all that we have. [Rashbam Sukkah ibid; P”M 625 M”Z 1 agrees with reason of Rashbam, as we rule like Rebbe Akiva versus Rebbe Eliezer]
 Vayikra 23:42
 Admur ibid and 429:4; Michaber ibid; Bach 625; Levush 625; Rashi and Ramban on Vayikra 23:43; Rebbe Eliezer in Sukkah ibid; See Birkeiy Yosef 625 in name of Toras Kohanim for opposite Girsa of opinions; See Bach and Taz 625 for different explanations of their debate
Other opinions: According to Rebbe Akiva, we slept in actual Sukkahs and not in clouds of glory. [Sukkah ibid]
 So is written in some prints of Admur ibid. In other prints the word says “Vichein”; See Likkutei Sichos 32:140