Not all comedy is funny. Dante's Divine Comedy is an obvious case in point. The main purpose of such comedies is not amusement but moral instruction, and reinforcement of the social order. Comedies traditionally end with marriages because marriage as a civil and religious ceremony is the basis of the family, and therefore of a stable, well-ordered society.
In The Merchant of Venice, Bassanio marries Portia, Gratiano marries Nerissa, and Lorenzo marries Jessica, who becomes a Christian in the process. Modern audiences often find the play's morality unduly harsh, but it has clear moral and religious messages. Shylock may be treated badly, but he is shown some mercy (since he is allowed to live) even after he himself has adamantly refused to show any. While all Shakespeare's comedies contain moral messages, The Merchant of Venice is particularly clear in this respect, since the most famous speech in the play is a homily on the value of mercy:
The quality of mercy is not strain'd,
It droppeth as the gentle rain from heaven
Upon the place beneath: it is twice blest;
It blesseth him that gives and him that takes:
'Tis mightiest in the mightiest: it becomes
The throned monarch better than his crown;
His sceptre shows the force of temporal power,
The attribute to awe and majesty,
Wherein doth sit the dread and fear of kings;
But mercy is above this sceptred sway;
It is enthroned in the hearts of kings,
It is an attribute to God himself;
And earthly power doth then show likest God's
When mercy seasons justice.
If Shylock seems like a tragic figure rather than a comic one by the end of the play, his tragic flaw was his obduracy in taking no account of this impassioned plea for mercy, as he continued in his quest for revenge. The audience is verbally reminded that God himself seasons his justice with mercy, and dramatically shown the awful consequences of failing to heed this warning.