Shaykh al-Islām—may Allah have mercy on him—was asked:
If a man performs a prayer as a precaution while doubting whether it is obligatory for him, may someone offering an obligatory prayer follow him as imam?
He answered:
By analogy with the school’s established rulings, this is valid, because the person in doubt performs it with the intention of fulfilling an obligation. This accords with what we have said concerning intention in cases of unconsciousness, even though we do not hold fasting to be obligatory. Likewise, we have said that someone who doubts whether his ablution has been invalidated should perform ablution.
The same applies to cases of doubt about whether purification, fasting, zakat, prayer, a ritual observance, expiation, or anything else is obligatory. This differs from someone believing an act to be obligatory and subsequently discovering that it was not. Differing rulings have been inferred concerning that case, since the act is actually voluntary, although he believed it to be obligatory. In the doubtful case, however, he intends the act as obligatory while remaining uncertain whether it is.