The Gemara in Sotah records that while the shaliach tzibbur recites Modim, the congregation does not merely stand silent but recites its own text, with several Tannaim and Amoraim contributing phrases that were ultimately combined, as brought by Beit Yosef, Orach Chayim 127:5 and paralleled in Jerusalem Talmud Berakhot 1:5; the reason given there is 'on that we thank You' — that God placed in our hearts the capacity to be bound to Him and to thank Him.
The practical reason given for this separate congregational text is to avoid any appearance that the congregation is silently rejecting or failing to affirm the chazan's words of thanks, since one does not answer Amen to one's own praise-like formula the way one does to a blessing; Rav Mordechai Eliyahu (Maamar Mordechai Limot HaChol 18:21) states explicitly that Modim D'rabbanan was instituted by the Sages so that the congregation not appear, God forbid, to be denying the chazan's words, and that each individual must bow slightly during it for the same reason.
The Rambam and the Tur record the practice of the whole congregation bowing with the chazan at Modim and reciting this text, rooting the law of universal bowing specifically here (as opposed to elsewhere in the Amidah) in the Yerushalmi's statement that all bow with the shaliach tzibbur specifically at Hoda'ah, cited in Mishneh Torah, Prayer and the Priestly Blessing 9:4 and Tur, Orach Chayim 127, and further summarized by Rav Eliezer Melamed (Peninei Halakhah, Prayer 19:8), who notes that its nusach differs from the Modim of the silent Amidah while its bowing laws are the same.
Beyond the halachic mechanics, several Hasidic expositions in the Siddur Im Dach frame the deeper purpose of Modim D'rabbanan: because the body's materiality obscures a person's recognition of what he owes God, the Sages instituted this additional thanksgiving as an acknowledgment of one's very capacity to give thanks, as explained in Siddur Im Dach 303d and Siddur Im Dach 303c, while Siddur Im Dach 306a adds that the matter is so wondrous that intellectual gratitude alone cannot reach it, requiring this deeper form of thanksgiving.
Rav Kook (Ein Aya, Berakhot 3:40) situates this communal dimension within a broader principle that matters of sanctity, like Kedushah, cannot be recited by an individual alone but require the plurality of the congregation, since it is only through the collective that God's holiness is truly revealed in service of Him.
On the practical performance of Modim D'rabbanan, Rav Menashe Klein (Mishneh Halachos 15:44) rules that the congregation should recite it softly and at a measured pace so as to bow and finish together with the chazan, while the chazan should extend his own blessing enough for most of the congregation to respond, and Rav Ephraim Greenblatt (Revavos Ephraim 5:69) rules that one should stand and bow specifically together with the shaliach tzibbur rather than bowing ahead of him, answering Amen immediately beforehand.
On a related question of error, Rav Menashe Klein (Mishneh Halachos 11:89) discusses the origin and purpose of Modim D'rabbanan as either supplementing the words of thanks in the Amidah's Modim or serving as the individual's own personal acknowledgment rather than one conveyed through the shaliach tzibbur, and rules that one who mistakenly recited it in place of Modim need not repeat the prayer once the blessing is finished, though should correct it if the error is noticed beforehand.