In the name of Allah,
The prostration of gratitude or sujood al Shukr is what a person does when blessed or protected from harm. It is recommended. The Shafis, Hanbalis, certain Hanafis, Ibn Habib the Maliki, and some Salaf hold this stance. Al-Mundhir, al-Qurtubi, Ibn Taymiyyah, Ibn Qayyim, al-Sanani, al-Shawkani, Ibn Baz, and Ibn Uthaymin all hold this position.
In the view of Abu Hanifah, Malik (in a well-known viewpoint), and al-Nakha’ie, it is not authorized, and Makruh. It says in Nur Al Idah [Hanafi],
‘’The prostration of gratitude is disliked according to Imam Abu Hanifa, in which one is not rewarded for doing, and its abandonment is better. However, Imam Muhammad and Imam Abu Yusuf held that it is an action that brings one closer to Allah in which one is rewarded for performing.’’[I] The Hanafi Madhhab has issued its official choice (fatawa) based on their opinion.
As for the act of praying two Rak’ahs to Allah out of gratitude on the occasion of receiving a blessing, this is an act that is without foundation.
Evidence:
After learning about Musailamah’s murder, Abu Bakr (R) prostrated. Umar (R) prostrated in submission upon the conquest of Yarmuk. Similarly, the Prophet (PBUH) often prostrated during such occasions.
Once the Prophet (PBUH) was lying with his head on ‘Aishah’s lap then a person came to inform the Prophet (PBUH) of the victory of a Muslim army over its enemies, so the Prophet (PBUH) stood and then fell into prostration and performed a lengthy prostration.[ii]
References:
[i] [Nur-Al Idah, The light of clarification, Hasan Shurunbulali, page 256
[ii] Reported by Ahmad, 5/45; al-Haakim, 4/291