If a prayer begins with a correct intention, does it become invalid if the worshipper subsequently intends to terminate it?
Chapter on the Description of Prayer
Al-Mughni
Book of Prayer
Primary text
If a worshipper enters the prayer with a valid intention and then forms the intention to cut it off and exit, the prayer becomes invalid. This is the position held by Al-Shafi'i. The evidence is that the worshipper has severed the effect of the initial intention before completing the prayer, which invalidates it, similar to saying the final salutation while intending to exit. Furthermore, intention is a condition for the entirety of the prayer; severing it invalidates the act due to the removal of its prerequisite condition.
Supporting text
Abu Hanifa holds that the prayer does not become invalid by merely intending to exit, because one entered a valid act of worship, and it should not be nullified by the intention to leave, analogous to the ruling concerning Hajj.