Short answer
The verse does not say earthquakes cannot happen. It says God (﷾) set the mountains firm "lest it should shake with you". The Arabic word there is tamida. It means to sway, tilt or be unsettled, like the deck of a ship. For an earthquake the Qur'an uses other words, and it tells of earthquakes striking. The Prophet (ﷺ) said that earthquakes would become many before the Last Day. So the verse is not a promise that the ground will never tremble. A builder who puts your house on firm foundations has not promised that it will never feel a tremor. Islam's answer is that God (﷾) made the earth a steady home for people, with the mountains set firm in it.
Full explanation
What the verses say
Three verses say that God (﷾) set firm mountains on the earth "lest it should shake" with its people. They are 16:15, 21:31 and 31:10. Each time the point is the same. The earth was made a steady place to live, with roads and rivers, rain and living things. The Arabic phrase is an tamida. It comes from the root m-y-d, the three letters the word is built from. That root is about swaying, tilting and being unsettled.
“And He has set up on the earth mountains standing firm, lest it should shake with you; and rivers and roads; that ye may guide yourselves;”
“And We have set on the earth mountains standing firm, lest it should shake with them, and We have made therein broad highways (between mountains) for them to pass through: that they may receive Guidance.”
“He created the heavens without any pillars that ye can see; He set on the earth mountains standing firm, lest it should shake with you; and He scattered through it beasts of all kinds. We send down rain from the sky, and produce on the earth every kind of noble creature, in pairs.”
The Qur'an's own words for an earthquake
When the Qur'an means violent shaking, it uses different words. The people of Thamud were seized by the rajfah, the tremor. The Hour, the end of the world, brings its zalzalah, its convulsion. The last day opens with the earth shaken by its zilzal, its quaking. So the Qur'an knows the earth can quake, and says so in plain Arabic. Reading 16:15 as "earthquakes are impossible" would set it against these verses. That is not the natural reading.
“So the earthquake took them unawares, and they lay prostrate in their homes in the morning!”
“O mankind! fear your Lord! for the convulsion of the Hour (of Judgment) will be a thing terrible!”
“When the earth is shaken to her (utmost) convulsion,”
The Prophet (ﷺ) spoke of earthquakes
The Prophet (ﷺ) said that earthquakes would become many, as one of the signs before the Hour. He taught these verses himself, and he foretold earthquakes. So he plainly did not read the verses as ruling earthquakes out.
Abu Hurayra reports that the Prophet (ﷺ) said the Hour will not come until knowledge is taken away, earthquakes become many, time passes quickly, trials appear, killing increases and wealth overflows.
Steady is not the same as never shaken
The earth was made stable for the people on it. That is not the same as saying it can never shake, even briefly and in one place. These are two different claims. Nor does the verse say that mountains stop the plates of the earth from moving. No Muslim needs to claim that. The plates are the huge slabs of rock that make up the earth's outer shell. Mountains often mark where the earth has moved. What the Qur'an does say is that mountains are set firmly in the earth like pegs. Separately, in 1855 George Airy, a British scientist, proposed that great mountain ranges such as the Himalayas have deep roots of crust below them. Later measurements confirmed it. The answer to the earthquake question does not depend on this.
“And He has set up on the earth mountains standing firm, lest it should shake with you; and rivers and roads; that ye may guide yourselves;”
“Have We not made the earth as a wide expanse, And the mountains as pegs?”
Explains the small pull of the Himalayas by proposing that a mountain range is held up by a root of lighter crust reaching down into the denser rock beneath, much as a floating block rides deep in water. This became the standard account of mountain roots.
The objection answered
Qur'an 16:15 — Surat al-Nahl (The Bee), verse 15
“And He has set up on the earth mountains standing firm, lest it should shake with you; and rivers and roads; that ye may guide yourselves;”
Cited for
Critics read the verse as saying mountains stop the earth from shaking. Earthquakes happen, and they are common in mountain ranges, so they say the verse is wrong.
The response
The verse does not use the Qur'an's word for an earthquake. Tamida means to sway or be unsettled. The Qur'an names earthquakes with rajfah and zilzal and describes them happening. The Prophet (ﷺ) foretold many of them. Nor does the verse say that mountains stop the plates of the earth from moving. So some earthquakes striking in mountain ranges do not clash with it. The verse speaks of the whole earth made a settled home for its people.
Where it lands — The verse says the earth was made steady for its people. It does not say earthquakes cannot happen, and the Qur'an itself describes them.
Perspectives
The Islamic perspective
The verses say God (﷾) made the earth a steady, settled home and set the mountains firm in it. They do not say earthquakes cannot happen. The Qur'an and the Prophet (ﷺ) both speak of earthquakes.
"Lest it should shake" translates an tamida, from a root about swaying and being unsettled. It is not one of the Qur'an's words for an earthquake.
The Qur'an names earthquakes with other words, rajfah and zilzal, and describes them striking.
The Prophet (ﷺ) said earthquakes would become many before the Hour.
A promise of a stable home is not a promise that the ground will never tremble. Firm foundations do not promise a house that never feels a tremor.
The Qur'an teaches that God (﷾) made the earth a settled home for people. He set the mountains firm in it.