Oh, wait, you thought that, just because Beowulf is heroic, virtuous, and brave, that he was going to live happily ever after?
Nope, that's not how ancient warrior culture rolled. The first rule of Anglo-Saxon epics is that a tragic defeat is way cooler than a triumph—especially if the tragic defeat is followed by a really expensive funeral.
Why are death and defeat better than victory? Well, those early medieval warriors were pessimists. After all, if nobody lives to be very old because almost everyone dies in battle, then you probably start thinking that death comes to us all, and the only thing that matters is how you meet your end.
To the Anglo-Saxons, the real test of a warrior isn't whether he can win a fight; it's what he'll do on the day he finally loses, and how he'll behave when he knows he's doomed to die. Then, after he's dead, you can see how much everyone else valued him by what amount of treasure there is at his funeral. Lots of gold and jewels equals a great man. It's pretty straightforward.
That's why, even though the ending of Beowulf might be a surprise to us as 21st Century readers, it wouldn't have been a surprise to the Anglo-Saxon audiences listening to a storyteller recite the epic in the 8th Century.
They weren't interested in experiencing a vicarious thrill of victory when the hero triumphed. They wanted to know whether he could actually face down certain death and not flinch—and not because he knew he'd win in the end, but because he cared about honor and valor more than about his own life.
That's why the narrator keeps ruining the ending for you, making references to Beowulf's eventual demise long before it actually happens. And, heck, if nobody can defeat you except a dragon, and you still manage to kill the dragon despite being mortally wounded yourself, then you're just that much more awesome.