Praise be to Allah.
Earthquakes: Great Signs of Allah
Earthquakes are one of the great signs of Allah in this universe, with which He tests His slaves as a reminder or to instill fear of Him or as a punishment. Man must remember, when the signs occur, his weakness, incapability, humble status before Allah and his need of Him, so he turns to Allah, may He be exalted and glorified, in supplication, beseeching and humility, in the hope that Allah will lift this great distress from the people.
Allah says (interpretation of meaning):
“Verily, We sent (Messengers) to many nations before you (O Muhammad). And We seized them with extreme poverty (or loss in wealth) and loss in health (with calamities) so that they might humble themselves (believe with humility). When Our torment reached them, why then did they not humble themselves (believe with humility)? But their hearts became hardened, and Shaytan (Satan) made fair-seeming to them that which they used to do. So, when they forgot (the warning) with which they had been reminded, We opened for them the gates of every (pleasant) thing, until in the midst of their enjoyment in that which they were given, all of a sudden, We took them (in punishment), and lo! They were plunged into destruction with deep regrets and sorrows.” [al-An’am 6:42-44]
Dhikr at the time of earthquake: Recommended?
Hence the fuqaha (may Allah have mercy on him) regarded it as mustahabb to offer a great deal of prayers for forgiveness and supplications, to beseech Allah and to give charity when earthquakes happen, as is also mustahabb when solar and lunar eclipses occur.
The great scholar Zakariya al-Ansari (may Allah have mercy on him) said:
“It is mustahabb for everyone to beseech Allah in supplication and so on when earthquakes and similar events, such as thunderbolts and strong winds, happen, and to offer prayers on his own in his house lest he be negligent, because the Prophet (blessings and peace of Allah be upon him) said, when the wind blew strongly: (O Allah, I ask You for its good and the good of what is in it and the good of what it is sent with, and I seek refuge in You from its evil and the evil of what is in it and the evil of what it is sent with.) Narrated by Muslim” (Asna al-Matalib Sharh Rawd al-Talib (1/288). See also Tuhfat al-Muhtaj (3/65))
Du’a at time of earthquake
But there is no evidence in the Sunnah -- as far as we know -- to suggest that there is a particular dhikr or du’a that it is mustahabb to recite when an earthquake occurs. Rather one should offer du’a as inspired by Allah to ask for mercy and help from Allah, may He be exalted and glorified, so that He might divert this calamity from the people.
Shaykh Ibn Baz (may Allah have mercy on him) said:
“What must be done at the time of an earthquake or other calamity, or an eclipse, strong wind or flood is to repent to Allah, may He be glorified, and to beseech Him and ask Him for well-being, and to remember Him a great deal and ask Him for forgiveness, as the Prophet (blessings and peace of Allah be upon him) said at the time of an eclipse: “When you see that, then turn to remembrance of Allah and call upon Him and ask for His forgiveness.” Agreed upon.
It is also mustahabb to show compassion to the poor and needy, and to give charity to them, because the Prophet (blessings and peace of Allah be upon him) said: “Show mercy, you will be shown mercy.” (Narrated by Ahmad)
And he said: “Those who show mercy will be shown mercy by the Most Merciful. Show mercy to those who are on earth and the One Who is in heaven will show mercy to you.” Narrated by al-Tirmidhi.
And he (blessings and peace of Allah be upon him) said: “The one who does not show mercy will not be shown mercy.” Narrated by al-Bukhari.
It was related from ‘Umar ibn ‘Abd al-‘Aziz (may Allah have mercy on him) that he used to write to his emirs when earthquakes took place telling them to give charity.
One of the means of being safe and sound from all evils is for those in authority to hasten to restrain the foolish and compel them to adhere to the truth, and to implement the laws of Allah among them, and to enjoin what is good and forbid what is evil, as Allah says (interpretation of the meaning):
“The believers, men and women, are Awliya (helpers, supporters, friends, protectors) of one another; they enjoin (on the people) Al-Ma‘ruf (i.e. Islamic Monotheism and all that Islam orders one to do), and forbid (people) from Al-Munkar (i.e. polytheism and disbelief of all kinds, and all that Islam has forbidden); they perform As-Salah (Iqamat-as-Salah), and give the Zakah, and obey Allah and His Messenger. Allah will have His Mercy on them. Surely, Allah is All-Mighty, All-Wise.” [al-Tawbah 9:71]
“Verily, Allah will help those who help His (Cause). Truly, Allah is All-Strong, All-Mighty. Those (Muslim rulers) who, if We give them power in the land, (they) enjoin Iqamat-as-Salah [i.e. to perform the five compulsory congregational Salah (prayers) (the males in mosques)], to pay the Zakah and they enjoin Al-Ma‘ruf (i.e. Islamic Monotheism and all that Islam orders one to do), and forbid Al-Munkar (i.e. disbelief, polytheism and all that Islam has forbidden) [i.e. they make the Quran as the law of their country in all the spheres of life]. And with Allah rests the end of (all) matters (of creatures).” [al-Hajj 22:40-41]
“And whosoever fears Allah and keeps his duty to Him, He will make a way for him to get out (from every difficulty). And He will provide him from (sources) he never could imagine. And whosoever puts his trust in Allah, then He will suffice him. Verily, Allah will accomplish his purpose. Indeed Allah has set a measure for all things.” [al-Talaq 65:2-3]
And there are many verses with similar meanings.” (Majmu’ Fatawa Ibn Baz (9/150-152)
And Allah knows best.