equal in recitation, then the one most knowledgeable about the Sunnah. If they are equal in knowledge of the Sunnah, then the one who migrated earliest. If they migrated at the same time, then the eldest.”
If both men are religiously upright, whichever is more knowledgeable about the Quran and Sunnah must be given precedence over the other. But if one of them is immoral—for example, known for lying, dishonesty, or similar conduct constituting sinfulness—while the other is a believer who fears Allah, then the latter has the greater right to lead the prayer, provided he is qualified to do so, even if the former is more proficient in recitation and more knowledgeable. For praying behind a sinful person is prohibited according to some scholars and discouraged, though not forbidden, according to others.
It has been related in a hadith:
“No immoral man is to lead a believer in prayer unless he overpowers him with a whip or stick.”
It is not permissible to appoint a sinful person to lead the prayer when a righteous person can be appointed. And Allah knows best.