Question:
When an Imam who engages in shirk (associating partners with Allahﷻ ) leads a Janazah prayer, Tawheed-oriented people avoid participating and instead go directly to the graveyard. Is this correct?
Answer:
First: Even if there is shirk in a mosque, that does not automatically make Janazah prayer invalid.
Second: Janazah prayers are not usually performed inside the mosque building. They are performed outside. Even in the Prophetﷻ ’s time, there was an open area (the suffah). Janazah had a designated place. It was not inside the mosque structure.
If an Imam clearly commits shirk — and it is confirmed — then yes, you should not follow him in prayer. That applies to all prayers.
But you must be certain. If someone ignorantly recites something thinking he is praising the Prophetﷻ , without intending shirk, you cannot label him a mushrik immediately. If you are certain he commits shirk and supports it, then you should not follow him.
But does that mean you abandon Janazah prayer entirely? No.
You can pray separately. Or you can pray at home before going. The Prophetﷻ prayed Janazah in houses as well.
Janazah prayer has great reward. Two qirats of reward. Many people making dua benefits the deceased. Why lose that reward?
If you know they are doing it wrongly, pray correctly yourself, then go to the graveyard.
Do not abandon Janazah prayer completely.