One reason is in order to remember The Temple and the
glory of Jerusalem during The Temple era as it says in the verse in Psalm
137:
If I forget you, O Jerusalem, let my right hand forget
its skill. Let my tongue adhere to my palate if I fail to recall you, if I
fail to elevate Jerusalem above my foremost joy.
So even at a time of "foremost joy," we smash a glass in
order to remember the destruction of The Temple.
Another reason is based on the Talmud in Tractate Berachot:
"[The Torah] says 'Serve G-d with fear and rejoice with
trembling'... Rav Ashi made a wedding for his son. When he saw that the
Rabbis were getting 'carried away' in their rejoicing, he brought out a
crystal glass and broke it before them and they became subdued."
The authors of the Tosefot state that this is the source
for the breaking of the glass at weddings. We learn from this that even at
an occasion of great rejoicing, one must take measures to ensure that the
celebration remains within bounds of propriety.
Sources:
- Shulchan Aruch, Orach Chaim 560:2.
- Tractate Berachot, pages 30b-31a.
- Tosefot - Tractate Berachot, page 31a, "Aissi...."