Epic heroes do not give up. Ever.
It is also part of the heroic code - loyalty, bravery, and generosity. He is just fulfilling this. He is remaining loyal to his people by battling on despite knowing he will lose. Beowulf is obviously being brave by fighting the dragon too. And he is being generous because when he kills the dragon, the cold and spoils will be sent back to his people. His death fulfills the heroic code and cements his reputation as a great warrior. Also, as a warrior, what better way to do? Facing great odds and almost single-handedly vanquishing such a great enemy as the dragon?
Beowulf has a strong sense of valor, and pride throughout this piece. Yet, he exhibits a Christ-like ideal in giving up his own life to save his people.