Evidence that it is permissible to separate from the imam for a legally recognized excuse is found in the Prayer of Fear: the first group prays one rak'ah with the imam, and when he rises for the second, they intend to separate from him, complete their second rak'ah, give the salām, and depart. (1)
Evidence that it is permissible to separate for a physical excuse is the case of the Companion who separated from Mu'adh ibn Jabal because he prolonged the prayer. (2)
An example is when something occurs to a person during his prayer that permits him to end it or shorten it: while praying behind the imam, he is afflicted by an excuse that makes it difficult for him to continue with the imam. We say to him: You may separate from the imam, shorten the prayer, and leave—unless separating will bring him no benefit. For example, if the imam is already shortening the prayer to the minimum required extent, then he gains nothing by separating and should not do so. But if the imam is observing the sunnah by praying unhurriedly, and the follower would suffer by remaining with the imam because he needs to relieve himself, then we say to him: Separate from the imam, shorten the prayer, give the salām, and leave.
If someone says: What do you say regarding a traveler who prays behind an imam praying four rak'ahs? Do you permit him, after praying two rak'ahs, to separate from the imam and give the salām, since a traveler shortens the prayer?
We say: We do not permit you to do that.
Then what is the difference between this case and that of one who prays Maghrib behind one who is praying Isha?
The answer: The difference between them is clear, because completing a four-rak'ah prayer is completing a prescribed form