Many are citing the Rambam AZ 2:2, and that is proper and to be expected. However I think it is slightly more nuanced, and this halakhah is balanced against דע מה שתשיב לאפיקורוס - knowing how to respond to an Apiqores (Abboth 2:14).
The Rambam (Perush ad loc) writes:
אף על פי שתלמד דעות האומות לדעת איך תשיב עליהם, השמר שלא יעלה בלבך דבר
מן הדעות ההם, ודע שמי שתעבוד לפניו יודע צפון לבך, והוא אמרו ודע לפני
מי אתה עמל, רצה לומר שיכוין לבו באמונת השם יתברך
Even though you study the opinions of the nations to know how to
respond to them, take care that nothing of those opinions arise in
your heart, and know that the One before whom you worship knows the
direction of your heart, and as it is said, "and know before whom you
labor", which is to say that you should direct your heart to belief in
God.
Indeed the Rambam makes clear in the Moreh (3:29) that he has studied all of the idolatrous works of the Sabeans. Facially this would appear to contradict the halakhah as he restates it in AZ 2:2, but with Abhoth 2:14 born in mind makes perfect sense.
To bolster this point and perhaps add a caveat, the Ribhash wrote concerning the Rambam (Vol 1, Res. 45):
כי הוא למד קודם לכן כל התורה כולה בשלימות: הלכות ואגדות, תוספתא, ספרא
וספרי וכוליה תלמודא. בבלי וירושלמי, כמו שנראה מספר משנה-תורה שחיבר,
וכדי להשיב את האפיקורס...כשהתלמיד אדם גדול מותר שיבור פסולת וישליך
הפסולת, כמו שאמרו שם "ר"מ רימון מצא, תוכו אכל קלינתו זרק"
For he had prior learned the entirety of the Torah, halakhoth,
aggadoth, Tosefta, Sifra, Sifri, the Babylonian and Jerusalem Talmuds,
as is apparent from his composition of the Mishneh Torah, and [he
studied external works] in order to respond to the Apiqores... and
when the student is a man of great standing he is permitted to peel
away the shell and cast it away, as our Sages taught (Hagigah 15b) R.
Meir found a pomegranate and ate its contents while throwing away its
peel [i.e. studied halakhoth from the heretic Aher].
According to the Ribhash, in order to engage in the process of learning such external works for the purpose of knowing how to respond to an Apiqores, one must already be at a high caliber of learning in their Torah. Then they may engage in a discerning process of תוכו אכל קליפתו זרק - consuming the valuable innards and tossing the outer peel/shell, which can be toxic/injurious.
Accordingly, it would seem that before reading such a work one ought be very honest with themselves about a) what is the purpose of their study, b) even if a legitimate reason motivates them - what is the leaning of their heart? and c) per the Ribhash, is one on a level of Torah mastery such that they can competently discern what to keep and what to toss.