The ancient tradition regarding Leonidas' ancestry was part of the historical record of the Greeks, and in his Histories, Herodotus included all information that he gathered in his investigations of Greek history.
Herodotus (5th century BC) is known as "the father of history," because his writing pioneered the field of historical research. Indeed, we get the word "history" from him. He called his writing about the Greeks and their wars with Persia the ἱστορία (historia), which in Greek meant "investigations." We now call his book "The Histories," but it could be called "The Investigations." As the History Channel notes, in doing his investigations, Herodotus "listened to myths and legends, recorded oral histories and made notes of the places and things that he saw." In other words, Herodotus tried to include all the stories he heard, including popular tradition or legend.
Herodotus records the genealogy of Leonidas in a way that emphasizes he is a great man descended from an even greater ancestor. Here is the section from his Histories that gives that impressive genealogy: