Praise be to Allah, and peace and blessings be upon the Messenger of Allah. To proceed:
There is no contradiction between the two verses, because the stretching out mentioned concerning this world is different from the stretching out that will occur on the Day of Resurrection.
Allah تعالى says:
﴿وَهُوَ الَّذِي مَدَّ الْأَرْضَ وَجَعَلَ فِيهَا رَوَاسِيَ وَأَنْهَارًا﴾ [Ar-Ra‘d: 3]
“And He is the One who spread out the earth and placed therein firm mountains and rivers.”
This means that He spread out the earth, expanded it, and prepared it for habitation and benefit, and placed in it mountains, rivers, and fruits.
As for Allah’s statement:
﴿وَإِذَا الْأَرْضُ مُدَّتْ وَأَلْقَتْ مَا فِيهَا وَتَخَلَّتْ﴾ [Al-Inshiqaq: 3–4]
“And when the earth is stretched out, and casts forth what is within it and becomes empty,”
this describes what will happen when the Hour is established. The earth will then be spread out and its expanse will increase, while its mountains, hills, and the familiar features upon it will be removed, until it becomes level and vast.
Allah تعالى says:
﴿وَيَسْأَلُونَكَ عَنِ الْجِبَالِ فَقُلْ يَنْسِفُهَا رَبِّي نَسْفًا فَيَذَرُهَا قَاعًا صَفْصَفًا لَا تَرَىٰ فِيهَا عِوَجًا وَلَا أَمْتًا﴾ [Ta-Ha: 105–107]
“And they ask you about the mountains. Say: ‘My Lord will blow them away completely, leaving them as a level plain. You will see therein neither crookedness nor unevenness.’”
Therefore, the stretching out of the earth on the Day of Resurrection is another stretching out, different from the one existing in this world. It will occur along with the transformation of the order of the universe and the disappearance of its familiar conditions, in preparation for the gathering and standing before Allah تعالى.
In summary: the stretching out of the earth in this world means spreading it out and preparing it for life. As for its being stretched out on the Day of Resurrection, it means that it will be spread out and expanded, while its mountains are removed and its conditions are transformed. Thus, there is no contradiction between the two verses.
And Allah تعالى knows best.