The reason why Nation state experiment failed in a lot of Muslim countries because they came from Empire or Kingdom rule then came colonialism.
Empires have always been diverse and you have numerous nations living in 1 empire. Lets narrow it down to ethnic groups, tribes and clans.
Lots of Islamic Empires of Turkic, Arab, African, Persian, Amazigh and other origins like Indian.
Why im including Indian because Muslim Empires that ruled India were not just Turkic, Afghan or Persian based they also included Indian elements hence why Baburs descendants overtime largely became Indian rather than Turkic.
Arabs in their case they usually tell themselves about the Arab caliphates that ruled usually see them as the ones to emulate.
Arabs and Turks may share the same religion also share some cultural aspects due to them mingling with each other for centuries.
Arabs will never see themselves apart of the Ottoman and Seljuk legacies largely due to them being Turkic.
To build a nation state you need to use history as a continutation. There hasnt been a Arab Empire or a kingdom in the Middle East for centuries. Im not including Oman and Morocco since they were largely their own for centuries. Oman has always been a different Arab country due to Ibadi Islam.
Turkiye has the Ottomans and Seljuks while Russia has the Soviets and the Tsars. China has Qing and the Ming.
Last Arab Empire or Caliphate was the Abbassids which collapsed in 1258. Middle East largely spent most of its time under foreign rule.
Its a bit of a offtopic. I do believe nation states are born out of sense of continuity to the old.
I understand where you are coming from, but IMO there is only so much to harness from empires and civilisations etc....and there can be good and bad regarding such as there are both objective and subjective things harnessed from it by the individual.
That is why statist operating principles need to be geared to being minimalist and focused as possible to that which is objective (within the nation)...i.e physical.
Law and order, security of the nation, administration, national infrastructure, long term merit institutions and so on and addressing any severe instances of market failure collectively by way of the state (in a market infancy period etc).
Things like religion, theology et al. are vast domains within the even larger domain of metaphysics.
The core self evident truths (preceding the nationstate formation) stemming from these can be harnessed and applied (regd the social contract and law etc which I mentioned earlier) without all the assorted baggage in the metaphysical alleyways (which are interesting to get into within bounds, but should not be wielded in the state) that will only impose costs.
A metaphysical+maximalist oriented state will do damage to the nation and start grievous erosions, conflicts (to add to any ongoing ones) and collapses....as it posits perfectionist utopia and make enemies among its own body quickly by power for power sake elitist capture and so on.
Marxism copies and pastes the pyramid (it perceives) and inverts it to an extreme materialist domain. It becomes its own religion effectively from its reactionary metaphysics.
The forces regarding this will happen somewhat inevitably over time in a relatively minimalist+focused state....so there is even less reason to make this easy from the get go.
Things can be compared and contrasted for example between the Ottoman empire ---- > nationstates occupying its former realm today and the same for say Qajar Iran.
The lack of proper balanced minimalist reset from Ataturk's revolution and republic.... shows up drastically now in modern day Iran's case.
The moulding of Ataturk in his life story.....one example is his basic realisation the metaphysics---statist danger.
He saw the strife, the fassad of co-religionists in the breakup of the Ottoman empire. That the raw metaphysical size of these things will always be far larger in number outside the Turkish people than inside it....the sheer population differential. This would be the danger if a quick circuit of it is given in the republic to be formed. Hence the minimalist approach with secularism instead. The resistance against over-secularisation (also a problem like I describe with the extreme form of it in say Marxism).... would be trusted to the people and communities and institutions formed in cohesion with the state's law and order and principles....that they hold what is best about their culture within them for the long run as well.
Iran's theocracy in comparison is heavily disjointed from its own population, does not work for their interests well....and instead meshes far more seamlessly with the larger region's sociological clay on offer. Hence proxy export model (by the state)....at long term cost to its nation.
The shah was essentially just as insular and bad regarding this....there was basically no commitment to a longer term process generated within Iran like Turkiye did.....so the state does tenuous ad hoc things relative to the nation. This nationstate is in the end in a bunch of trouble long term till the next revolution hits it, then have to see how the state shapes up then and the accounting of the costs.
In China this can be seen in quite short span of time too in the 20th century. The attempted principled crafting in Ataturk kind of fashion by Sun Yat Sen....but insufficient time and space for it to set in (like Ataturk was able to harness with the intelligentsia and context he had)....correlated to the vastness and context of China.
The quick usurpation (for a number of reasons) by his successor, the civil war, the foreign invader war interjecting during it as well.... and then rise of a despot who went for the maximalist approach with Marxist statism and the "constant internal war" (and communism export to world etc) with the nation to be slaved to this first and foremost, no matter the cost. The better balance and operating conditions (ability of some virtuous cycles to nest within larger non-virtuous one) only really came to bear after his death for a reason....but there is still cult image legacy and so on that harnesses the metaphysics and its ego and so on.
Really the topic is a vast one. Turkiye was very lucky to have Ataturk around at that time it did.