Praise be to Allah.
Yes, it is mustahabb to pray when one of these signs happens, such as eclipses, earthquakes, violent storms, persistent and frightening winds, and destructive floods, because it is narrated in a saheeh report from Ibn ‘Abbaas (may Allah be pleased with him) that he prayed when an earthquake struck Basra, offering a prayer like the eclipse prayer. Then he said: This is how prayers should be offered at the time of these signs.
Narrated by Ibn Abi Shaybah, 2/472; ‘Abd ar-Razzaaq, 3/101; al-Bayhaqi in as-Sunan al-Kubra, 3/343. And he said: This is proven from Ibn ‘Abbaas. End quote. Classed as saheeh by al-Haafiz in Fath al-Baari, 2/521
Al-Kasaani (may Allah have mercy on him) said:
It is mustahabb to pray at all times of alarm, such as when there are strong winds, earthquakes, darkness, and ongoing rain, because they are causes of alarm and fear.
End quote from Badaa’i‘ as-Sanaa’i‘, 1/282
It says in Manh al-Jaleel Sharh Mukhtasar Khaleel (1/333): It is recommended to pray when there is an earthquake or similar frightening signs such as epidemics and plagues, individually or in congregation, two rak‘ahs or more. End quote.
The Hanbalis limited the recommendation of prayer to earthquakes, because that was narrated from Ibn ‘Abbaas. As for other signs, it is not prescribed to pray at those times.
See: Kashshaaf al-Qinaa‘, 2/66
Ash-Shaafa‘i (may Allah have mercy on him) was of the view that it is prescribed to pray at times of these signs individually, but it is not prescribed to pray in congregation on such occasions.
See: al-Majmoo‘, 5/61, by an-Nawawi.
Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) was of the view that it is prescribed to pray in the event of all signs. He (may Allah have mercy on him) said: The eclipse prayer may be offered on all occasions when there is a sign, such as earthquakes and other events. This is the view of Abu Haneefah and was narrated from Ahmad. It is also the view among our companions and others.
End Quote from al-Fataawa al-Kubra, 5/358
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) mentioned three opinions concerning the matter, the third of which is that this prayer may be offered at the time of any frightening sign. Then he (may Allah have mercy on him) said: This last view is the view favoured by Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him), and it is a very strong view. This is the more correct view.
End quote from ash-Sharh al-Mumti‘, 5/93
And Allah knows best.