«مَا فِيهِمْ إِلَّا مَنْ يُحْفَظُ عَنْهُ وَلَا يُتَحَفَّظُ مِنْهُ»
Among them was only someone worth learning from, not someone against whom one had to be on guard.
Mā fīhim illā man restricts the group’s description through negation and exception. Man is a relative pronoun, and the following verb phrases describe the person meant. The attached pronouns in ʿanhu and minhu return to that same antecedent.
The two verbs are not synonyms: one concerns what may be transmitted or memorized from a person, the other whether one must guard oneself against that person. Reading the relative clause as a unit preserves this contrast.