The Talmudic roots of the shofar's spiritual power are already established in the Gemara (Rosh Hashanah 16a), which teaches that the shofar on Rosh Hashanah crowns God as King, causes Israel's remembrance to rise before Him for good, and evokes the merit of the Akeidah — and in the Gemara (Rosh Hashanah 16b), which adds that sounding the shofar confuses the Satan, so that a year in which it is not sounded is liable to suffer misfortune because the Satan was not confused.
The institution of blowing the shofar throughout Elul is traced directly to the events of Rosh Chodesh Elul at Sinai: Pirkei DeRabbi Eliezer (46:2) records that when God told Moshe to ascend the mountain on Rosh Chodesh Elul to receive the second Tablets, a shofar was sounded through the camp so that Israel would not again err after idolatry, and God was exalted through that very shofar — and therefore, that passage states, the Sages enacted that the shofar be sounded on Rosh Chodesh Elul every year; Yalkut Shimoni on Nach (754:2) cites the same event and the same enactment, grounding it in the pasuk "Elohim has ascended with a blast" (Amos 3:6).
The Tur (Orach Chayim 581) synthesizes the two purposes Chazal assigned to the Elul shofar: to warn Israel to do teshuvah — citing Amos 3:6, "When a ram's horn is sounded in a city, do the people not take alarm?" — and to confuse the Satan, and on that basis records the Ashkenazic custom to sound the shofar every morning and evening after prayer throughout the month.
The Shulchan Arukh (Orach Chayim 581:1) codifies the Sephardic practice of rising before dawn for Selichot from Rosh Chodesh Elul through Yom Kippur, while the Rema records the Ashkenazic practice of blowing the shofar after Shacharit — and in some places after Arvit as well — beginning from Rosh Chodesh, with Selichot beginning from the Sunday before Rosh Hashanah.
The Rambam (Mishneh Torah, Repentance 3:4) opens the shofar's meaning to a deeper dimension of machshava: even though the Rosh Hashanah shofar is a Scriptural decree, it carries an inner message — "Awaken, O sleepers, from your sleep; arise, O slumberers, from your slumber; examine your deeds and return in teshuvah, and remember your Creator" — a call to moral awakening that animates the entire season beginning in Elul.
The Arukh HaShulchan (Orach Chaim 581:1–5) draws these threads together, explaining that because the shofar saved Israel from sin and because Elul is the month designated for teshuvah as the final month of the year preceding the days of judgment — invoking "If a shofar is sounded in a city, will the people not tremble?" — all of Israel adopted the custom of sounding the shofar after prayer throughout the month; the Kitzur Shulchan Arukh (128:1) similarly frames the forty days from Rosh Chodesh Elul through Yom Kippur as days of Divine favor and mercy, specially suited for teshuvah, because it was on Rosh Chodesh Elul that Moshe ascended to receive the second Tablets.
The Mishnah Berurah (581:1–3) adds an additional layer of asmakhta, noting that the initials of the pasuk אֲנִי לְדוֹדִי וְדוֹדִי לִי spell אלול, and that its final letters total forty, corresponding to the forty days from Rosh Chodesh Elul through Yom Kippur during which teshuvah is most readily accepted — a period in which one's heart draws near to God and God draws near to accept that teshuvah with love; the Mishnah Berurah (581:2) further records the custom of reciting Mizmor LeDavid (Tehillim 27) morning and evening throughout this period.
On the level of machshava, the Shem MiShmuel (Mishpatim 10:14) explains that during Elul the thirteen Attributes of Mercy are opened to Israel, and — drawing on the Arizal — teaches that every arousal from below is preceded by a Divine arousal from above; the shofar and prayers of Rosh Hashanah are the arousal from below that responds to a prior heavenly arousal, and the roshei teivot of אֲנִי לְדוֹדִי וְדוֹדִי לִי capture this mutual drawing-near that Elul is designed to initiate.
The Shenei Luchot HaBerit (Rosh HaShanah, Ner Mitzva 2) reasons that since Elul is the final month of the year, it is the fitting time to do teshuvah for whatever one has damaged throughout the year, so as not to enter Rosh Hashanah — the Day of Judgment — while still stained by sin, and he finds an allusion to this in the roshei teivot of וּמָל ה' אֱלֹקֶיךָ אֶת לְבָבְךָ וְאֶת לְבַב זַרְעֶךָ, which likewise spell אלול.
Mareh Yechezkel (Shabbat Shuvah 2:2) raises a striking machshava question: the standard explanations of the Elul shofar — awakening to teshuvah and confusing the Satan — apply to the masses, but for Torah scholars who are already engaged in Torah study and thereby breaking the forces of impurity, those reasons do not apply; he concludes that the sounding of the shofar in Elul must therefore carry a deeper, hidden reason, as do all the mitzvot.
The Maamar HaChochmah situates the shofar within a cosmic arc: Maamar HaChochmah (Chelek 1, 6:6) teaches that the first reinforcement of good over evil was achieved through the shofar of Matan Torah, the ultimate repair will be achieved through the great shofar of the future, and the Rosh Hashanah shofar was therefore ordained to strengthen the repair already wrought at Sinai and to prepare for the repair yet to come — a framework that gives the Elul shofar its place within that larger chain; Maamar HaChochmah (Chelek 1, 6:4) adds that the shofar's very power, through its sounding below and its root above, is to sustain the good and subdue the evil.