Firstly: The Ruling of the Prostration of Gratitude
It is mustahabb to perform the prostration of gratitude when blessings appear anew and when hardships are removed. This is the position of the Shafi`is, Hanbalis, some Hanafis, Ibn Habib the Maliki, and a group of the Salaf. It is the chosen opinion of Ibn al-Mundhir, al-Qurtubi, Ibn Taymiyyah, Ibn al-Qayyim, al-San`ani, al-Shawkani, Ibn Baz, and Ibn `Uthaymin.
Secondly: Purity for the Prostration of Gratitude
Being in a state of purity is not a condition for the prostration of gratitude. This is the position of some Malikis, Ibn Taymiyyah, Ibn al-Qayyim, al-Shawkani, al-San`ani, Ibn Baz, and Ibn `Uthaymin.