The Torah itself provides the foundational reason: Vayikra 23:42-43 states that the commandment is so that future generations will know that God made the Israelite people dwell in booths when He brought them out of Egypt.
Building on that pasuk, the Sefer HaChinukh (325:2) explains the root of the commandment as recalling the great miracles God performed for Israel in the wilderness — specifically His sheltering them with clouds of glory from sun and frost — and adds that through remembering His wonders we become careful in His commandments and fitting to receive His goodness, while the Tur (Orach Chayim 625) identifies those same clouds of glory as the referent of the booths in the verse, noting that the Torah ties the commandment to the Shemot precisely because that event is something witnessed and heard and cannot be denied, testifying to the Creator's sovereignty over all.
The Gemara derives the practical scope of this dwelling from the word 'תֵּשְׁבוּ' — 'you shall dwell' — reading it as 'כְּעֵין תָּדוּרוּ,' meaning in the manner in which one normally resides: the Gemara (Sukkah 28b) rules that all seven days a person renders his sukkah permanent and his house temporary, bringing his fine vessels and bedding into the sukkah, and eating, drinking, and spending time there, and the Shulchan Arukh HaRav (Orach Chayim 639:1-20) states explicitly that the Torah obligated a person to leave his ordinary dwelling and reside in the sukkah with his beds, linens, and utensils of daily use.
The codifiers translate this principle into a comprehensive rule of eating: the Rambam (Mishneh Torah, Shofar, Sukkah and Lulav 6:5-7) rules that one must eat, drink, and live in the sukkah all seven days just as he dwells in his home throughout the year, and the Shulchan Arukh (Orach Chayim 639:1) codifies the same, specifying that fine dishes, linens, and drinking vessels belong in the sukkah, while the Levush (Orach Chayim 639:1) explains that eating and drinking in the sukkah is the expression of making it one's primary residence.
On the question of when eating in the sukkah is an absolute obligation versus a conditional one, Midrash Tanchuma Buber (Pinchas 13) records the dispute: Rabbi Eliezer holds one is obligated in fourteen meals — one by day and one by night for each of the seven days — while the Sages hold there is no fixed number, except for the first night of the festival, and the Beit Yosef (Orach Chayim 639:11) explains the Talmudic reasoning that the first night is mandatory by analogy to the first night of Pesach, after which eating in the sukkah is required only if one eats at all.
The Mishnah Berurah (639:1-35) specifies that on the first night of the festival one is obligated to eat at least a kezayit of bread in the sukkah, derived from the same gezeirah shavah linking Sukkot to Pesach, while the Ben Ish Hai (Ha'Azinu 1-15) adds the practical ruling that one should not eat from midday of Erev Sukkot onward, so that one will eat that obligatory first-night meal with appetite.
The Gemara illustrates how seriously the Sages took even incidental eating in the sukkah: the Gemara (Sukkah 26:2) records that Rabban Yochanan ben Zakkai and Rabban Gamliel had even a taste of cooked food and two dates brought up to the sukkah, though Rabbi Tzadok ate less than an egg-bulk outside the sukkah, reflecting the ruling that a casual snack below that threshold may be eaten outside.
The Mishnah Berurah (625) adds a dimension of intentionality, explaining that the commandment is observed specifically in the seventh month — when people normally move indoors — so that dwelling in the sukkah is visibly an act of divine command rather than mere summer convenience.
Beyond memory and law, the sources offer deeper layers of meaning: מנורת המאור, נר ג כלל ד, חלק ו פרק א, וראה שם עוד explains that the commandment comes precisely after the harvest, when storehouses are full and a person is tempted toward self-reliance, and therefore God commands leaving the sturdy house for the sukkah so that one will place trust in God and recognize that all his bounty and protection come from Him; the Sefat Emet (Devarim, Sukkot 13:5) similarly teaches that the commandment of the sukkah embodies the quality of trust in God — leaving one's permanent dwelling so as not to rely on wealth and possessions but on God alone.
The Sefat Emet (Devarim, Sukkot 19) adds that the dwelling in the clouds of glory was a hidden wonder, and the mitzvah of sukkah each year awakens an illumination from that original dwelling that transcends nature, while the Zohar (Emor 103a) teaches that a person should show himself as dwelling beneath the shade of faith — the seven clouds of glory with which God surrounded Israel — and that 'you shall dwell in sukkot seven days' corresponds to those seven precious clouds, which are bonds of faith.
The Minchat Chinukh (325:9) addresses the character of the sukkah obligation itself in terms of the two categories of positive commandments, and Likkutei Torah (Sukkot 80d-81a) and the Tanya (Likkutei Amarim 36:1) — which states that the purpose of creation is God's desire to have an abode in the lower worlds — together provide a Hasidic framework in which the sukkah's encompassing structure embodies the drawing down of divine presence into the physical world.