Praises and glorifications are due and belong to Allah, and may His choicest favors, salutations and blessings be upon Prophet Muhammad, his family and all the companions.
Sajdat al-Shukr (prostration of gratitude) is prescribed for anything that makes one happy, whether it is attaining some benefit or warding off some harm. The evidence (daleel) showing the legality of this is found in the traditions (Ahaadith) narrated from Prophet Muhammad (May the peace and blessings of Allah be upon him) and reports on the authority of the sahaaba (companions) may Allah be pleased with them. Among the traditions is the Hadeeth of Abu Bakrah (may Allaah be pleased with him), who said that when the Prophet (peace and blessings of Allaah be upon him) heard any news that made him glad, he would fall down prostrating to Allaah, may He be Exalted. (Reported by the five except al-Nisaa’i; al-Tirmidhi said, it is hasan ghareeb). According to the version narrated by Ahmad: he saw the Prophet (peace and blessings of Allaah be upon him), when news reached him that his troops had prevailed over their enemy, he was lying with his head in ‘Aa’ishah’s lap, then he got up and fell in prostration. (Reported by Ahmad, 5/45; al-Haakim, 4/291).
Another hadeeth is that narrated by ‘Abd al-Rahmaan ibn ‘Awf, who said: the Prophet (peace and blessings of Allaah be upon him) went out to the place where the sadaqah (charitable donations) was kept, then he faced the Qiblah and fell in prostration, remaining like that for a long time. Then he raised his head and said, “Jibreel came to me with good news, he said, ‘Allaah says to you, “Whoever sends blessings on you, I will send blessings on him, and whoever sends greetings of peace to you, I will send greetings of peace to him,”’ so I prostrated in thankfulness to Allaah.” (Narrated by Ahmad. Al-Mundhiri said: the hadeeth of Sajdat al-Shukr came from the hadeeth of al-Baraa’ with an authentic chain of transmission, and from the hadeeth of Ka’b ibn Maalik and others.)
The reports include the following:
Abu Bakr (may Allaah be pleased with him) prostrated when he heard the news that Musaylimah had been killed. (Reported by Sa’eed ibn Mansoor in his Sunan).
‘Ali ibn Abi Taalib(may Allah be pleased with him) prostrated when he found Dhu’l-Thadiyah among the Khawaarij. (Reported by Ahmad in al-Musnad)
Ka’b ibn Maalik prostrated at the time of the Prophet (peace and blessings of Allaah be upon him) when he was given the glad tidings that Allaah had accepted his repentance. (The story is agreed upon).
The above traditions and reports which are all from authentic sources clearly depict the legality of the prostration for showing gratitude, however, it must be emphasized that majority of the Muslim Scholars of the pious predecessors (salaf) opined that, being in the state of purification, or ablution, facing the qibla and covering ones awra are not necessary conditions for the performance of prostration of thankfulness. This is the opinion of many scholars of the Maaliki school of thought.It is also the opinion of many scholars such as Ibn Jarir At-Tabari, Ibn Hazm, Sheikh Al-Islam Ibn Taimiya and his student Ibn Al-Qayyim, as well as As-San’aani, and Shawkaani. It was regarded the preponderant view by most of our contemporary scholars such as sheikh Abdul-Aziz Ibn Baz, Sheikh Salih Ibn Utheimeen and Sheikh Abdulla Ibn Abdur-Rahmaan Ibn Jibreen, may Allah have mercy on all of them.