Imaam al-Mirdaawi said in al-Insaaf (2/154): The author– Ibn Qudaamah – said that two conditions apply for sujood to be made up later:
It should be in the mosque
A long time should not have passed.
This is the right opinion, as he stated.
Imaam Ahmad said: He should do the sujood if the time that has passed is short, even if he has left the mosque.
He also said: He should do the sujood even if the time that has passed is long, or he has spoken or left the mosque. This is the opinion favoured by Shaykh al-Islam [Ibn Taymiyah]. Al-Ikhtiyaaraat al-Fiqhiyyah, p. 94.
In Al-Rawd al-Murabba’ Sharh Zaad al-Mustaqna’ (2/461) it says: (If he forgets), i.e., he forgets to do the sujood al-sahw which should be done before the salaam, (and he says salaam), then he remembers, (he should do the sujood) and it is obligatory (if the time that has passed is short)… If he has said salaam – and if a long time has passed according to what is ordinarily regarded as a long time, or he broke his wudoo’, or he left the mosque – he does not need to do the sujood, and his prayer is still valid.
In Al-Sharh al-Mumti’ by Shaykh Muhammad ibn Saalih al-‘Uthaymeen (3/537), it says: The phrase ‘If he forgets and says salaam, he should still do the sujood if the time that has passed is short’ refers to the sujood that should be done before the salaam, when he has already said the salaam. He should do this sujood if the time that has passed is short, otherwise he no longer has to do it, and his prayer is still valid.
A man may forget the first tashahhud, so he has to do sujood al-sahw before the salaam, but he forgets and says the salaam. If he remembers shortly afterwards, he should do the sujood, but if he remembers a long time afterwards, he no longer has to do it. This is why he said ‘He should do sujood if only a short time has passed. If he has left the mosque, he should not come back to do this sujood – he no longer has to do it, which is unlike when he has said salaam before completing the prayer. In the latter case, he should come back and complete it, because he has omitted an obligatory act.
Shaykh al-Islam Ibn Taymiyah said: Indeed, he should do the sujood, even if a long time has passed, because this will make up for what was missing. So when he remembers it, he should make up for it.
But the most likely opinion is that suggested by the author (may Allaah have mercy on him), which is that if a long time has passed, the person no longer has to do the sujood, because sujood al-sahw is obligatory (waajib) either to make the prayer valid or it is waajib in the prayer as part of the prayer, so it is connected to the prayer and is not a separate prayer. We say that the Prophet (peace and blessings of Allaah be upon him) said: “Whoever sleeps and misses the prayer, as soon as he remembers, let him pray.”(Reported by al-Bukhaari (597) and Muslim (684) from the hadeeth of Anas). But we cannot use this evidence with regard to sujood al-sahw, because it is part of something else. If a person remembers soon afterwards, he should do it, otherwise he does not have to do it. And Allaah knows best.