This is in Moreh Nevukhim (3:50):
והם אלו הספורים אשר ספר בתורה, אשר יחשבו רבים שאין תועלת בזכרם, בספרו הסתעף המשפחות מן נח ושמותם ומקומותם, וכן בני שעיר החורי וספר המלכים אשר מלכו בארץ אדום וכיוצא בהם, וכבר ידעת אמרם שמנשה הרשע לא היה מרבה מושבותיו הפחותים רק בדקדוקי אלו המקומות, אמרו היה יושב ודורש בהגדות של דופי, היה אומר לא היה לו למשה לכתוב אלא ואחות לוטן תמנע, ואני אודיעך כלל אחד, ואשוב אחר כן אל הפרטים כאשר עשיתי בטעמי המצות. דע כי כל ספור שתמצאהו כתוב בתורה הוא לתועלת הכרחית בתורה, אם לאמת דעת שהוא פנה מפנות התורה, או לתקון מעשה מן המעשים, עד שלא יהיה בין בני אדם עול וחמס. ואני אסיר לך הספק, כאשר היתה פנת התורה שהעולם מחודש ואשר נברא תחלה היה איש אחד ממין האדם והוא אדם הראשון, ולא היה באורך הזמן אשר מאדם עד משה רבינו רק אלפים וחמש מאות שנה בקרוב, ואילו בא להם זה הספור לבד היה האדם מסופק בדבר, כי נמצאו אז בני האדם מפוזרים בקצוות הארץ כלה ומשפחות חלוקות ולשונות חלוקים רחוקים מאד, והוסר הספק הזה ביחסם כלם וזכרון הסתעפם, וזכר שמות המפורסמים מהם פלוני בן פלוני ושנותיהם, ולהגיד מקום שכנם, והטעם המביא להתפזרם בקצות הארץ, והטעם המביא להחלק לשונותם, ושמתחלה היו במקום אחד ושפה אחת לכולם, כי כן ראוי להיותם בני איש אחד.
THERE are in the Law portions which include deep wisdom, but have been
misunderstood by many persons.; they require, therefore, an
explanation. I mean the narratives contained in the Law which many
consider as being of no use whatever; e.g., the list of the various
families descended from Noah, with their names and their territories
(Gen. x.); the sons of Seir the Horite (ibid. xxxvi. 20-30); the kings
that reigned in Edom (ibid. 31, seq.); and the like. There is a saying
of our Sages (B Ṭ. Sanh. 99b) that the wicked king Manasse frequently
held disgraceful meetings for the sole purpose of criticising such
passages of the Law. "He held meetings and made blasphemous
observations on Scripture, saying, Had Moses nothing else to write
than, And the sister of Lotan was Timna" (Gen. xxxvi. 22)? With
reference to such passages, I will first give a general principle, and
then discuss them seriatim, as I have done in the exposition of the
reasons of the precepts.
Every narrative in the Law serves a certain purpose in connexion with
religious teaching. It either helps to establish a principle of faith,
or to regulate our actions, and to prevent wrong and injustice among
men; and I will show this in each case.
It is one of the fundamental principles of the Law that the Universe
has been created ex nihilo, and that of the human race, one individual
being, Adam, was created. As the time which elapsed from Adam to Moses
was not more than about two thousand five hundred years, people would
have doubted the truth of that statement if no other information had
been added, seeing that the human race was spread over all parts of
the earth in different families and with different languages, very
unlike the one to the other. In order to remove this doubt the Law
gives the genealogy of the nations (Gen. v. and x.), and the manner
how they branched off from a common root. It names those of them who
were well known, and tells who their fathers were, how long and where
they lived. It describes also the cause that led to the dispersion of
men over all parts of the earth, and to the formation of their
different languages, after they had lived for a long time in one
place, and spoken one language (ibid. xi.), as would be natural for
descendants of one person. (Friedlander Translation)