What is the ruling on praying behind an imam who shaves his beard?
Shaving the beard is not a major sin. Indeed, the injunction to grow one’s beard is a contentious matter among scholars. An act that is legally prohibited must be agreed upon by all scholars. The imam who shaves his beard must not be avoided and it is permissible to pray behind him.
Al-Bukhari narrated that ‘Abdullah Ibn ‘Umar prayed behind Al-Hajjaj Ibn Yusuf Al-Thaqafi and ‘Abdullah Ibn Mas‘ud prayed behind Al-Walid Ibn ‘Uqba Ibn Abu Ma‘it who used to drink alcohol. Al-Walid once led the morning prayer and performed four rak’as [cycle of prayer] instead of two. The Companions also used to pray behind Ibn ‘Ubayd who was accused of atheism and of calling the people to error. So [if these people could lead prayers], a fortiori anyone who knows how to pray.
There is no doubt that it is more advantageous to pray behind a righteous person rather than behind someone who is corrupt. Yet, even if the behavior of an officially recognized prayer leader [i.e. whose job is prayer imamate] is suspect, there is no proscription in Islamic law which forbids praying behind him. However, it is obligatory to advise him [to mend his ways]. [In this respect] Ibn Majah and Ibn Haban recorded the following narration: “There are three whose prayers will not be accepted: an imam who is unpopular [because of his conduct]; a woman who allows her husband to wake up [the morning after an argument] while he is still angry with her and two brothers when they are fighting.”
Although it is disliked to pray behind a corrupt person, it is not unlawful. In addition to the above, this is supported by the hadith: “Pray behind the trustworthy and the corrupt, and perform jihad with the trustworthy and the corrupt” [recorded by Al-Bayhaqi].
Shaving the beard
It is not a grave sin for a man to shave his beard. Rather, it is among the [many] matters upon which the scholars have not reached an agreement on whether they are obligatory or merely recommended. According to the basics of Islamic law, a matter upon which the scholars disagree may not be generally prohibited for Muslims. The imam who shaves his beard should not be avoided and it is permissible to pray behind him.
And God the Almighty knows best.