What to Do If There Are Two Reasons for Sujud As-Sahw
Question

I want to ask about the one who does something extra in his prayer out of forgetfulness, and in the same prayer he forgets something. Should he do the two prostrations of forgetfulness (sujud as-sahw) before the salam or after the salam, or what?
Praise be to Allah.Sujud As-Sahw: Before or after the Salam?
Regarding the issue of the prostration of forgetfulness , and whether it should be before the salam or after, there is a difference of opinion among the scholars. The view that seems most likely to be correct is that if the worshipper does something extra in the prayer by mistake, he should do the prostration of forgetfulness after the salam, and if he omits something, he should do that prostration before the salam. But if he is not sure, then the matter is subject to further discussion. If he thinks that one of the two possibilities is more likely, then he should prostrate after the salam, but if he does not think that one of the two possibilities is more likely, then he should prostrate before the salam.
What to do if there are two reasons for Sujud As-Sahw
If there are two reasons, one of which dictates that he should do the prostration before the salam, such as forgetting the first tashahhud , and the other dictates that the prostration should be after the salam, such as adding a prostration or a rak‘ah by mistake, then it is sufficient for him to do one prostration for forgetfulness , and what appears most likely is that it should be before the salam, especially if he was leading a prayer as an imam, so as to make things easier for the worshippers and to prevent confusion for any latecomer among them if he gets up straight after the salam [to complete his prayer].
Ibn Qudamah (may Allah have mercy on him) said: 
“If someone makes two mistakes or more of the same type, it is sufficient for him to do the two prostrations for all of them, and we do not know of anyone who disagreed concerning that. If the mistakes were of two different kinds, the same applies. Ibn al-Mundhir narrated that as one view from Ahmad, and it is the view of most of the scholars, including an-Nakha‘i, ath-Thawri, Malik, al-Layth, ash-Shafi'i, and ashab ar-ra-y, because of the words of the Prophet (blessings and peace of Allah be upon him): “If one of you forgets [and makes a mistake in his prayer], let him prostrate twice.” This includes mistakes in two different positions in the prayer, because the Prophet (blessings and peace of Allah be upon him) made a mistake and said the salam, then he spoke after his prayer, then he did the prostration of forgetfulness once for both of them.
And that is because this prostration (sujud as-sahw ) is to be done at the end of the prayer, so that it may include all mistakes. If that were not the case, it would have to be done straight after each mistake.
Moreover, this prostration is prescribed to compensate for shortcomings in prayer, even if they are many. The evidence for that is the fact that mistakes in the prayer all come under the same heading, and if they are made up for [by doing the prostration of forgetfulness], the worshipper will not need to do that prostration again.
Once this is established, what is meant by two types of mistakes is that one type dictates that the prostration of forgetfulness should be done before the salam and the other type dictates that it should be done after it…
Based on that, if the worshipper makes two mistakes, one of which dictates that the prostration of forgetfulness should be done before the salam and the other dictates that it should be done after it, then he should do the prostration for both before the salam, because it comes earlier and is more important, and because the prostration before the salam became obligatory due to there being a reason for it. Therefore he should do it [before the salam], as if he had no other mistake to be compensated for. Thus if he does this prostration, the second prostration will be waived.” (Al-Mughni (1/387)
Shaykh Ibn ‘Uthaymin (may Allah have mercy on him) said: 
“If there are two reasons [for doing the prostration of forgetfulness ], one of which dictates that the prostration should be done before the salam and the other dictates that it should be done after the salam. It may be said: he should see which is greater in number, such as if he said the salam before completing his prayer, and he bowed twice in one rak‘ah, and he forgot to recite the first tashahhud. In this case, there are two causes which dictate doing the prostration of forgetfulness after the salam, namely the extra bow (rukoo‘) and saying salam before completing the prayer; and we have one reason which dictates doing the prostration of forgetfulness before the salam, namely forgetting to recite the first tashahhud. So in this case, he should do the prostration of forgetfulness after the salam.
Another example: a man bowed twice in one rak‘ah, and forgot to say Subhana rabbiy al-‘azim when bowing and Subhana rabbiy al-a‘la when prostrating. In this case, there are two reasons for doing the prostration of forgetfulness before the salam, namely omitting the tasbih when bowing and when prostrating, and there is one reason which dictates doing the prostration of forgetfulness after the salam, which is the extra bow. Therefore he should do the prostration of forgetfulness before the salam.
The correct view is that it should be done before the salam in all cases, because compensating for a mistake which dictates that the prostration of forgetfulness should be done before the salam is obligatory, and the place for that is before the salam. Therefore hastening to compensate for the prayer before it is completed is more appropriate than delaying the action that will compensate for it.” (Ash-Sharh al-Mumti‘, 3/398)
And he (may Allah have mercy on him) was asked: If there is more than one mistake in the prayer, and one of them dictates that the prostration for forgetfulness should be done before the salam and the other dictates that it should be done after the salam, when should it be done in this case?
He replied:
“This issue is based on knowing the definition of the type of mistake which dictates that the prostration of forgetfulness should come after the salam. In every case where the cause was doing something extra, such as if the worshipper prostrated three times, or got up for a fifth rak‘ah, then remembered and sat back down, in this case the prostration for forgetfulness should be done after the salam. However, it should be done before the salam if he omits one of the obligatory parts of prayer, such as if he stands up before reciting the first tashahhud, or he forgets to say Subhana rabbiy al-a‘la when prostrating or Subhana rabbiy al-‘azim when bowing. In this case, the prostration of forgetfulness should come before the salam. But if he made two mistakes, one of which dictates that the prostration of forgetfulness should come before the salam and the other dictates that it should come after the salam, which one should we give precedence to? 
The scholars say that he should give precedence to that which dictates that it should be done before the salam, so that when he finishes his prayer it will be complete. So, for example, if a man forgets to recite the first tashahhud after the first two rak‘ahs, then sits to recite the first tashahhud in the third rak‘ah, thinking that it is the second, then he remembers and stands up and completes the prayer, then in this case he has made two mistakes: firstly, he forgot to recite the first tashahhud and, secondly, he recited the tashahhud in the wrong place in the prayer. In this case, we say: Do the prostration of forgetfulness before the salam.” (Al-Liqa’ ash-Shahri, 28/11)
And Allah knows best.