Praise be to Allah
Earthquakes are one of the great signs of Allah subhanahu wa ta’ala 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 subhanahu wa ta’ala and his need of Him, so he turns to Allah in supplication, beseeching and humility, in the hope that Allah subhanahu wa ta’ala will lift this great distress from the people.
Allah subhanahu wa ta’ala says (interpretation of meaning):
“Verily, We sent (Messengers) to many nations before you. 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’aam 6:42-44]
Hence the fuqaha’ (may Allah have mercy on them) regarded it as mustahabb [recommended] 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.
When the wind blew strongly, the Prophet salAllahu ‘alayhi wa sallam said,
اللَّهُمَّ إِنِّي أَسْأَلُكَ خَيْرَهَا ، وَخَيْرَ مَا فِيهَا ، وَخَيْرَ مَا أُرْسِلَتْ بِهِ ، وَأَعُوذُ بِكَ مِنْ شَرِّهَا ، وَشَرِّ مَا فِيهَا ، وَشَرِّ مَا أُرْسِلَتْ بِهِ
“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.” [Muslim]
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 subhanahu wa ta’ala to ask for mercy and help from Him, so that He might divert this calamity from the people.
One should also make it a habit to recite the morning and evening supplications and seek Allah’s protection. One dhikr that one must recite every day is:
It was narrated that Abu Al-Yasar said: The Messenger of Allah salAllahu ‘alayhi wa sallam used to say:
[Transliteration: Allahumma inni a’udhu bika minat-taraddi, wal-hadmi, wal-gharaqi, wal-hariqi, wa a’udhu bika, an yatakhabbatanish-shaitanu ‘indal-mawti, wa a’udhu bika an amuta fi sabilika mudbiran, wa a’udhu bika an amuta ladigha]
For more Protection Du’as see: The Book of Seeking Refuge with Allah
Shaykh Ibn Baaz (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 subhanahu wa ta’ala 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 salAllahu ‘alayhi wa sallam 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 salAllahu ‘alayhi wa sallam said, “Show mercy, you will be shown mercy.” [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.” [Tirmidhi]. And he salAllahu ‘alayhi wa sallam said, “The one who does not show mercy will not be shown mercy.” [al-Bukhari]
It was related from ‘Umar ibn ‘Abd al-‘Azeez (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 subhanahu wa ta’ala says (interpretation of the meaning):
“The believers, men and women, are Awliyaa’ (helpers, supporters, friends, protectors) of one another; they enjoin (on the people) Al‑Ma‘roof (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 (Iqaamat-as-Salaah), and give the Zakah, and obey Allah and His Messenger. Allah will have His Mercy on them. Surely, Allah is All-Mighty, All-Wise.” [at-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‑Salaah [i.e. to perform the five compulsory congregational prayers (the males in mosques)], to pay the Zakah and they enjoin Al‑Ma‘roof (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 Qur’an 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.” [at-Talaaq 65:2-3]
And there are many ayaat with similar meanings. End quote.
Majmoo’ Fataawa Ibn Baaz (9/150-152).
And Allah knows best.