The Quran says that no disaster befalls the earth or ourselves unless it is in a Book before it is brought about, that Allah created everything in due measure, and that He will test people with fear, hunger and loss. It does not claim to tell us why this earthquake struck this town. Only Allah knows His reasons for a particular event. The Prophet ﷺ said that when Allah wants good for someone He afflicts them, so a person's suffering cannot simply be read as a sign of how Allah sees them, and hardship can be a mercy and cleansing for the believer.
The Prophet ﷺ said that the plague is a punishment that Allah sends on whom He wills, and that He made it a mercy for the believers: a believer who stays in his town patiently during a plague, knowing that only what Allah has written will reach him, receives the reward of a martyr. In Sahih Muslim he named those who die of plague, an illness of the stomach, drowning or a collapsing building among the martyrs. For Muslims who lose loved ones in disasters, these are real sources of consolation.
The Prophet ﷺ also taught that whoever relieves a believer of a worldly distress, Allah relieves one of his distresses on the Day of Judgment, and Muslims regard help for the afflicted as an obligation, not an option. Honesty requires adding that for those who do not believe in an afterlife, or who have lost a child in an earthquake, no framework removes the pain. Islam does not pretend otherwise. It offers a way to carry the loss with meaning and with hope for a reunion in a world where such things do not happen.