When a person prays in a synagogue with a congregation, his prayer is heard (see Berachot 6a). Even someone who missed praying in a minyan has a mitzvah to pray in the synagogue, since it is a permanent and special place of holiness in where prayer is more accepted (Shulchan Aruch 90:9).
However, when the minyan is held in a different place, it is preferable to pray with the minyan rather than individually in the synagogue. If there is a small minyan in the synagogue and a larger minyan elsewhere, although there is merit to praying in the company of many, the value of praying in a synagogue is greater (Pri Megadim; Mishnah Berurah 90:27-28).
Every community has an obligation to fulfill the mitzvah of building a synagogue which will be their mini-sanctuary (mikdash me’at) and where people can pray in a minyan. As it is written (Ezekiel 11:16), “I have been for them a small sanctuary,” and Rabbi Yitzchak interpreted, “These are synagogues and study halls” (Megillah 29a).
Reish Lakish says whoever has a synagogue in his city and does not pray there is called a bad neighbor. Moreover, he brings exile upon himself and his descendants. Those who arrive early to synagogue to recite Shacharit and are late to leave after praying Ma’ariv merit long life (Berachot 8a; Shulchan Aruch 90:11).
It is a mitzvah to run to synagogue just as it is a mitzvah to run to perform every mitzvah, in order to express one’s passion for matters of sanctity, as it says (Hosea 6:3), “We will race on in order to know Hashem.” Likewise, when one leaves the synagogue, he should walk slowly, so that he not appear happy to leave the synagogue (Shulchan Aruch 90:12).