He—may Allah Most High have mercy on him—was asked:
A man proposed marriage to a free woman who has a guardian other than the judge. He brought witnesses whom he knows to be sinful, but whose testimony the judge would accept were they to testify before him. Is the woman’s marriage valid with them as witnesses? If it is valid, is it disliked?
He answered:
Yes, the marriage is valid under these circumstances. The “uprightness” required of the two marriage witnesses means only that their outward standing is unblemished and that they display no manifest sinfulness. If they are sinful in private, but this is not apparent and their outward standing remains unblemished, the marriage contracted with them as witnesses is valid according to the sounder of the two scholarly views within the schools of Ahmad, al-Shāfiʿī, and others.
If the two marriage witnesses were required to have their uprightness formally attested before the judge, most people’s marriages would not be valid without that attestation. Yet it is known that, during the time of the Messenger of Allah—may Allah bless him and grant him peace—and of Abū Bakr, ʿUmar, ʿUthmān, and ʿAlī, people contracted marriages in the presence of others among them, even though those present had not had their uprightness formally attested before those in authority.
Some jurists hold that the two witnesses must be demonstrably upright. These witnesses, however, are accepted witnesses before the judges, who recognize their uprightness, even if some of them are sinful in reality. Thus, on either view, the marriage is valid with them as witnesses, even if they are sinful in private. And Allah knows best.