Reverse analogy (qiyās al-ʿaks)
Among the kinds of analogy is what is called “reverse analogy,” which consists in assigning to the branch the opposite of the original’s ruling because the branch possesses the opposite of the original’s effective cause.
They illustrate this with the Prophet’s saying: “In the sexual act of any one of you there is charity.” They asked, “Messenger of Allah, if one of us satisfies his desire, will he receive a reward for it?” He replied, “Tell me: if he were to place it in what is forbidden, would he incur sin? Likewise, when he places it in what is lawful, he earns a reward.” (1)
Thus the Prophet ﷺ gave the branch—lawful intercourse—the opposite ruling of the original—unlawful intercourse—because the branch contains the opposite of the original’s cause. He affirmed a reward for the branch since it is lawful intercourse, just as the original incurs blame because it is unlawful intercourse.