לרפואת אסתר רות בת נעמי שרה בתוך שאר חולי ישראל
The Rambam writes in Hilchos Talmud Torah [4/1]:
Similarly, one should not study from a teacher who does not follow a proper path, even though he is a very wise man and his [instruction] is required by the entire nation, until he returns to a good path, as [implied by Malachi 2:7]: "For the priest's lips shall keep knowledge, and they shall seek Torah from his mouth, because he is a messenger from the Lord of Hosts."
Some commentary:
Similarly, one should not study from a teacher who does not follow a proper path, even though he - the teacher
is a very wise man and his [instruction] is required by the entire nation, until he returns to a good path - Mo'ed Katan 17a relates that there was a Torah sage whose knowledge was needed by his community. However, because of his unsavory behavior, RavYehudah placed him under a ban of ostracism.
If a teacher resembles "a messenger - The Hebrew malach also means angel.
of the Lord of Hosts," seek Torah from his mouth. - Implied is that in addition to having knowledge and the ability to communicate it, a teacher must be a paradigm of Torah behavior, fit to be emulated by his students.
If he does not, do not seek Torah from his mouth. - Chaggigah 15b questions how Rabbi Meir would study from Acher, a great sage who scorned the observance of mitzvot. It explains that Rabbi Meir followed the instruction of Proverbs 22:17: "Turn your ear, hear the words of the wise, and direct your heart to My intention," which implies that one can "hear the words of the wise" and, instead of being influenced by them, "direct your heart to My (God's) intention."
The Talmud continues, explaining that only a sage of stature who can "suck a pomegranate and discard its shell" may follow such a course of behavior. Most people should refrain from studying under such teachers.
Accordingly, the Lechem Mishneh concludes that the Rambam did not quote the passage from Chaggigah because, at present, there are none who are of a stature great enough not to be influenced by a teacher of improper character.
The Sefer Kovetz notes that the Rambam mentions this verse in the beginning of his introduction to the Guide to the Perplexed, alluding to the fact that, in composing that work, he had to follow Rabbi Meir's example and study under teachers whose behavior he would not desire to emulate. Nevertheless, this did not represent a contradiction to his omission of this teaching in the Mishneh Torah. We find that under extraordinary conditions, it is permitted to follow a minority opinion in the Talmud. Hence, when the Rambam saw the need to write a text like the Guide to the Perplexed, he felt that under such conditions, he should follow Rabbi Meir's example.
[from Chabad.org]
So here it is: If a rabbi is guilty of crimes of a sexual nature, if he is dishonest, if he is a person who habitually speaks lashon hara, embarrasses people in public, expresses undue hatred toward other Jews etc. etc. then one is not allowed to learn from him until he does teshuva.
It is so disturbing to me how this Rambam is ignored and people flock to hear and even throw money - big money - at unruly characters. Even if his Torah is so awesome that all of Klal Yisrael needs it, one is still not allowed to learn from him.
Some sefarim say that one who is sinful is not able to understand the true intention of the Torah and whatever he says will be somehow inaccurate. But the Rambam seems to be saying that his Torah can be awesome, yet one still may not learn from him.
This is a topic that deserves more attention.