Our Sages ordained that the mitzva of hearing the shofar is integrated into the special berakhot added in the Amida of Musaf on Rosh Ha-shana: Malkhuyot, Zikhronot, and Shofarot. This enhances both the shofar-blowing and the prayers. This is not a prerequisite for fulfilling the mitzva, though; when the shofar-blowing cannot be integrated into the prayers, prayers and shofar-blowing may be separated. Moreover, the integration of the berakhot and the shofar-blowing was ordained only for communal prayer; someone praying alone may not blow the shofar during the Amida (Rosh Ha-shana 32a, 34b; SA 592:1-2).
Originally, the shofar was blown and the special berakhot were recited during Shaḥarit, for those who are enthusiastic perform a mitzva at the earliest opportunity (“zerizim makdimim le-mitzvot”). Later, at a time of anti-religious persecution, shofar-blowing was outlawed by the government. Enemy soldiers would try to catch Jews blowing shofar on the morning of Rosh Ha-shana. So the Jews instituted that the shofar be blown, and the special berakhot recited, at Musaf, which can be prayed in the afternoon. Even after the ban on shofar-blowing ended, the time did not revert back, out of fear that the persecution would be renewed. Eventually the custom of blowing the shofar during Musaf took root (Rosh Ha-shana 32b; Tosafot and Ritva ad loc.). Some maintain that it is actually preferable to blow during Musaf, since the Musaf offering was a central mitzva of the holiday, and the Musaf prayer corresponds to it (one view in y. Rosh Ha-shana 4:8).
The Sages also instituted shofar-blowing before Musaf and permitted sitting for these blasts; they are therefore known as teki’ot di-meyushav (sitting teki’ot). Even though le-khatḥila it is preferable for both shofar-blower and listeners to stand while the mitzva is being fulfilled, the Sages permitted the listeners to sit before Musaf in order to show that the teki’ot blown later, during Musaf (teki’ot di-me’umad), are the primary ones, for which one must stand. Indeed, the custom of Sephardim and Yemenites is to sit for the teki’ot before Musaf. Nevertheless, Ashkenazim commonly stand for these teki’ot because they are the first shofar blasts and one fulfills his basic obligation with them (SA 585:1; MB ad loc. 2).
According to the Gemara (Rosh Ha-shana 16a-b), the reason the Sages instituted shofar-blowing while sitting before Musaf and then again while standing during Musaf is “to confound the accuser (satan).” Rashi explains that when the satan sees that the Jews love the mitzvot so much that they blow even more blasts than the Torah requires, he is silenced. Ramban explains that the shofar blasts have the special power to bind the Jews to their Father in Heaven. This confounds the satan during the first teki’ot, and thus he is unable to prosecute during the Amida. Others say that the prosecutor can prosecute only once. When the shofar-blowing starts before the Amida, he lays out his case, so he has nothing left to say during the Amida (Raavad). Still others say that the primary manifestation of the satan is as the evil inclination. This inclination is thwarted by the many shofar blasts, which inspire us to repent (Ran). Perhaps during the first set of blasts, one is so excited that he is unable to focus properly; later, after he has heard thirty blasts, he is calmer and can focus properly.