بسم الله الرحمن الرحيم
(Fatwa: 666/664/N=06/1435)
If there is a mosque nearby where the imam follows the Shariah completely then you should offer salah behind him. And if there is no other mosque nearby or the imam there too is not complying Shariah then instead of offering salah alone you should offer salah behind such imam. Hence in this case you should only offer salah with jamah and not offer alone.
قال فى الدر (مع الرد كتاب الصلاة، باب الإمامة 2:301 ط مكتبة زكريا ديوبند): وفى النهر عن المحيط: صلى خلف فاسق أو مبتدع نال فضل الجماعة اهـ فى الرد: قوله: “نال فضل الجماعة” أفاد أن الصلاة خلفهما أولى من الانفراد لكن لا ينال كما ينال خلف تقي ورع … اهـ
Allah knows Best!
Darul Ifta,
Darul Uloom Deoband