a track race almost finisehd
Well, the first reason is that back then, in Dante's time, "comedy" didn't really mean funny. In this case, it meant that even though the whole story/poem is full of despair and torture and torment, it actually ends with a happy ending. Back in Dante's era, this meant that instead of being a tragedy, this epic poem was considered a comedy.
Consider Shakespeare's work Romeo and Juliet. It ends with the two young lovers dying, right? That is a tragedy. There is no happiness there. But at the end of Inferno, Dante the Pilgrim actually succeeds in his goals. <span />