Why is Hrothgar's lineage given in Beowulf?Why is Grendel's lineage given?
The lineage is to establish Hrothgar's rightful succession as king. It also supposes that Grendel's own ancestry goes back to the Biblical Cain, which sets up the story of a justifiable king and is people versus an alleged monstrous descendant of Cain: in other words, a battle worth fighting, especially by a warrior with Beowulf's credentials.
Another reason lineages were important to epic and heroic poems (and of course, histories) is that these were written records of praise, completely factual or not. They were predominantly written about, or for, kings, whereas now, it is just as, or more democratic to write about people of all walks and classes. But one of the things this epic establishes is that characters like Beowulf are worth writing about: maybe for is bravery, or for his generosity. "Lofgeornost," the poem's last line, means "most desirous of praise." As a king himself, Beowulf would be worthy of being written about, but it was customary to record the lineage of kings simply because they were kings: any acts of bravery, generosity, etc. just gave more to write about: more 'lofgeornost.'
Concerning Hrothgar's lineage being given in the epic Beowulf, not to mention Grendel's, I have the short answer for you. Someone else my give you specifics, I'll answer in general terms.
One's lineage explains where one comes from, and an epic pits hero against hero. Hrothgar's lineage demonstrates how powerful and glorious his ancestors were, while Grendel's demonstrates how evil and fallen his ancestors were. In order for Grendel to be such a terrible monster, he must conquer a powerful opponent. Eventually, in order for Beowulf's victory over Grendel to be monumental, Grendel must be as evil as evil can get. An epic is not an epic without epic forces doing battle. The lineages demonstrate the monumental heroes involved.