It is a mitzva to engage in building a sukka. According to the Sages of the Yerushalmi, one even recites a berakha upon doing so: “Who has sanctified us with His commandments and commanded us to make a sukka” (“la’asot sukka” – y. Berakhot 9:3; y. Sukka 1:2). However, in practice we follow the ruling of the Bavli and recite a berakha on the mitzva when we fulfill it, namely, when we sit in the sukka (Menaḥot 42a; SA 641:1).
Nevertheless, putting up a sukka clearly involves a mitzva element. The pious and virtuous would hurry to begin building the sukka right after Yom Kippur, so as to go directly from one mitzva to the next. They try to finish it by the next day, for when one has an opportunity to do a mitzva, he should make sure not to miss out (Maharil; Rema 624:5, 625:1).
According to Beit Shammai, one must build a sukka with the intention to fulfill the mitzva of the festival with it, as we read, “You shall hold (ta’aseh, lit. ‘make’) the seven-day festival of Sukkot” (Devarim 16:13). Without such intent, the sukka is invalid. However, the halakha follows Beit Hillel’s view that one need not put up the sukka specifically for the mitzva of the festival. Rather, as long as he built it to provide shade, it is kosher. Therefore, a sukka built by shepherds or guards to protect themselves from the sun is kosher, as is a sukka made by a non-Jew to provide himself with shade (Sukka 8a-b; SA 635:1). However, the Sages say that if a sukka was not built for the mitzva of the festival, le-khatḥila something should be added to it before the festival. For example, one could add a square tefaḥ of sekhakh or a strip of sekhakh that extends the length of the sukka (Yerushalmi; MB 636:4). The same applies to an “old sukka” – a sukka from a previous year that was never taken down. Technically it is kosher, but since it was put up for a previous year, it does not count as having been put up for this year’s mitzva. Therefore, le-khatḥila one should add either a square tefaḥ or a strip of sekhakh along its length (SA 636:1; MB ad loc. 7).
If a sukka was put up to provide privacy, it is invalid since it was not intended for shade. Similarly, if one put up a sukka to serve as his permanent home, it is invalid even if the roof is made of kosher sekhakh, since it is not a temporary residence. One who wants to use such a sukka for the mitzva would have to remove all of the sekhakh and replace it while having the mitzva of sukka in mind.
The halakha is that a sukka put up by a non-Jew or a woman is kosher (Sukka 8a-b; SA 14:1, 635:1). Despite this, some say that le-khatḥila one should be fastidious and have it built by a male Jew over the age of 13 (deferring to Rabbeinu Tam, who maintains that only one who is obligated in the mitzva may put up the sukka). This is the position of Magen Avraham 14:3, Bikurei Yaakov 635:2, and Binyan Shlomo 1:43. However, the widely accepted position is that a sukka put up by a non-Jew or a woman is kosher even le-khatḥila.