Peace be upon you. According to Grand Ayatollah Khamenei, if the justice of the imam is established to the follower by any means, it is permissible to follow him, and the congregational prayer is valid. Justice is a psychological state that consistently leads to piety, preventing the commission of forbidden acts and neglecting obligations. It is sufficient to ascertain it through good outward appearance, whether or not it leads to certainty. Justice can be established through any means that provides trust and reassurance, even if it comes from following a group of knowledgeable and righteous individuals.
According to Grand Ayatollah Sistani, justice is a condition for congregational prayer, and it is not permissible to pray behind a corrupt person. Justice must be established through one of the following means: 1) direct knowledge or reassurance obtained from rational sources like testing; 2) testimony from two just witnesses; 3) good outward appearance, which refers to good conduct and religious behavior, and can also be established through the first two means.
May you be successful in all good deeds.