The follower sincerely attempted to pray under an apparently valid imam. That good-faith ignorance is distinct from the legal validity of the imamate.
Under the Hanafi ruling, an imam whose purity was absent had an invalid prayer, and the follower’s prayer dependent on that imamate must be repeated. Subsequent discovery does not repair the original defect.