I am aware that this is a touchy subject, as well as probably a complex one, and that there might be many different theories as it's not such a straightforward objective fact, but that is precisely why I am asking this question here on r/AskHistorians.
I've always wondered what concurrence of events and ideologies led to both many Western Christians slowing losing their faith, as well as to many Muslims staying (or possibly growing more) attached to theirs.
Your question is hard to answer because it's based on inaccurate but widespread assumptions. It implies that there are few religious countries that are heavily Christian, but that all Muslim-majority countries are heavily Muslim, but this is false. If you look to Eastern Europe, Latin America, and Africa, you'll see many overtly non-secular governments. And a 2010 Gallup poll found that, for example, religion is far less important in the daily lives of people in Uzbekistan and Kazakhstan than it is in the US, Greece, Portugal, or Italy (Gallup, 8/31/2010).
Teasing things apart: First, there are a lot of Muslim-majority countries, but I think you're more interested in countries wherein Islam is the state religion. That includes formal Islamic Republics (Afghanistan, Iran, Mauritania and Pakistan) and countries not specifically named that (Iraq, Yemen, Algeria, Maldives and Bangladesh) but in praxis similar. Lots of other countries are secular but Muslim-majority, eg Azerbaijan, Gambia, Indonesia, Uzbekistan, Kazakhstan, etc. For what its worth, England, Denmark, Argentina, Costa Rica, Liechtenstein, etc. all have some form of state Christianity. Anyhow, i presume we're focusing here on Islam as state religion.
A big part of your question here hinges upon the idea of an unchanging middle east, or minimally, a teleological progression of history towards secularism. This, though, is also inaccurate. If you look back to the mid-twentieth century, you'll find that middle eastern governments were in many cases more secular than they are today. I'm mostly going to talk a lot about Iran for simplicity, because I think it looms large in the Western imaginary, and is also a useful case studies. It is one of the bedrocks of the Islamic Revivalist movement that spread across the Islamic world in the 1970s, and inspired many others. The other two more major events were conflicts in Israel/Palestine and the Soviet–Afghan War, although related events were happening in Egypt, Libya, and other places. I will talk about the former two as well after I provide the Iran case study. What links these events are a resistance to Western imperialism and frustrations with economic stagnation and class immobility under economic liberalism/modernization. A pre-existing pan-Arabic sentiment helps explain how Islamic Revivalism spread so quickly. Pan-Arabism (like Pan-Americanism and Pan-Africanism) had its roots in the late-nineteenth century, but an inflection of religiosity came later as a result of the events I'm describing.
In 1953, Iran had been amidst the sort of modernization efforts that had consumed much of the world in the early 20th century. The democratically elected Prime Minister Mohammad Mosaddegh had begun a crackdown on foreign companies, and particular, had cracked down on BP (British Petroleum) for its extractivism. When BP wouldn't play ball with an audit, the Mosaddegh government moved to nationalize the oil industry. In response, the British and USian governments moved to overthrow Mosaddegh via covertly backing a coup. This was called "Operation Ajax" and resulted in consolidated power of the monarchy ("The Last Shah"), which became authoritarian.
As the saying goes, "politics makes strange bedfellows". Resistance to the Shah came from all sides. The Shah's government was largely concerned with secular resistance, and devoted most of its efforts to tamping down on that. As Ali Mirsepassi argues, "With the growing discontent of the Iranian population over the regime's policies, and with the elimination of the secular oppositional forces by the regime's police forces, the emergence of a religious oppositional movement behind Khomeini became possible" (Mirsepassi 67). In other words, the US-back Shah's effort to crack down on secular resistance, especially secular resistance coming from the left (remember, this is the Cold War era), religion was the least obstructed path of resistance.
In the mid-60s, the man who would come to be known as Ayatollah Khomeini was arrested for speaking out against the regime, and was jailed for 1.5 years before being exiled for nearly 15 years in Iraq. He was a charismatic, populist Islamic philosopher who crafted a sort of resistance theology. He'd early on reported beliefs in the necessity for a democratic Iran, but he'd not stick to it.
Meanwhile, in the late 70s, resistance was rising from all sides. By 1979, the Iranian military said they'd "remain neutral" in any disputes between the Shah and the people, which marked the end of the Shah. To make a very long story short, Islam became a sort of resistant nationalism, a way to advocate for self-rule and resist the imperialist interference of western, at least nomimally Christian, powers. Khomeini was a thought leader on this, advocating for a sort of pan-Islamic world resistant politic.
Beyond the Iran case, another factor to the rise of Islamic Revivalism was disappointment and frustration with regard to losses to Israel, especially the Six-Day War. In the popular imaginary in retrospect, it came to be seen as something of a religious war rather than one of territory. The result of this was the widespread conclusion that Israelis had more religious faith than the Arab alliance. Thus, it became a catalyst for intensified faith.
Meanwhile, at the same time that everything is happening, the Soviet are supporting the pro-Soviet , secular Afghani government fighting the Mujahideen, a religious, right-wing group of rebels. Afghanistan had historically been a secular country (and in fact, one with fairly high gender equity), but this fight became a proxy war in the cold war. The Mujahideen received funding from the US, as well as Iran and other anti-Soviet forces, which helped them expand their influence and power, which in turn spread Islamic Revivalism. The war and resultant instability made way for the Taliban to take over in the mid-90s.
A sort of tl;dr is that many Muslim-majority countries experienced a resurgence of religiosity in the late 20th century as a result of economic disappointments, cold war machinations from world powers combined, and a larger global groundswell against western imperialism.
Mirsepassi-Ashtiani, Ali. "The crisis of secular politics and the rise of political Islam in Iran." Social Text 38 (1994): 51-84
Mamdani, Mahmood. Good Muslim, Bad Muslim: America, the Cold War, and the Roots of Terror. Harmony, 2005.
This is going to be a fairly surface level answer for what is a very complicated question. Questions trying to tie national identity and religiosity are never going to be easy- and across the Muslim world there is going to be a wide variety of answers. This answer is going to focus mostly on the Arab world- I don't know much about Muslim identity in Malaysia or Indonesia. And even then, the counties that consider themselves "Arab" is still somewhat of a nebulous answer. But for the sake of a simple answer, this is going to focus mostly on what we consider "The Middle East."
As far as speaking for the Arab world, it's really important to recognize that the view of Islam as inseparable from the cultural identities of Muslim majority countries is a relevantly recent phenomena and can be traced back to at the very earliest to roughly the early 1800s- far removed from widespread adoption of Islam in the region. But it becomes more widespread in the 20th century as secularist movements find themselves with few allies as the 20th century progresses.
Wahabbi and The House of Saud- the highly literalist view and what is commonly considered fundamentalist today only took over what is now Saudi Arabia in the mid 1820s- and was seen as widely unorthodox across many of the Ulama (religious scholars) in the broader Ottoman sphere. Other prominent Muslim Leaders at the time such as Muhammad Ali of Egypt took little attention to Islam, and instead directed their attention to industrialization, to great success I may add. The House of Saud is important, and we'll come back to them later.
The major turning point is with the aftermath of WWI and the advent of early Arab nationalism. The Ottoman Empire, which existed in various states of power for well over hundreds of years is toppled, and the Arab world is cut apart under British and French subjugation in a plan known as Skyes-Picot. The Middle East is divided around mostly arbitrary lines- trying to draw lines that fairly divide ethnic groups is never really a focus of Imperialists. The various arab leaders who aligned themselves with the British and French in WWI in exchange for their own political sovereignty find themselves left out of the discussion when it comes to who controls the middle east- they are left without any self-determination.
So now the people of the middle east find themselves under varying degrees of foreign occupation- some areas such as Syria are under active heavy fighting against French occupation from 1920-23, whereas Iraq during the British mandate was less hands on. Ideologically, there are two major forces that begin to establish themselves as an organized resistance to imperialism- the Secularists, and the religious fundamentalists / hard liners. Both are trying to accomplish the same goal- self determination and an end to imperialism. The secularists were the driving force against imperialism in Egypt- Gamel Abdel Nasser's vision of secularism remained the main face of secularism in the middle east until the Arab spring. The new Egyptian government promoted secularist-nationalism as their vision for the 20th century in the Arab world.
Many counties in the Middle east followed suit in some form of secularist government- in the 1960s- Egypt, Syria, Iraq, Iran, Jordan, Lebanon- all of these governments were secularist.
Multiple things all start to rapidly change the geopolitical landscape starting in the 1970s.
The massive failure of the Arab States against Israel in the 1967 6 day war begin to shake the ideological foundations of secularism. There is a marked difference in the framing of Arab v. Jew in the 1967 war compared to Muslim v. Jew in the 1973 Yom Kippur War.
The 1970s oil crisis and the creation of OPEC. OPEC was initially expected to be a pan-arab bulwark against the west, but there wasn't fair equity across the pact. Inadvertently, OPEC became a vehicle for Saudi Arabia to begin exporting it's version of Islam.
The 1979 Iranian revolution. While the revolution in the moment was an opportunity for many different political actors, very quickly the revolution turned into a Shia Theocracy led by Ayatollah Khomeini. Worth noting this also provides a huge geopolitical rift in now there is a regional Shia power that exports its influence and will lead to a brutal war against the secularist Iraq.
The Soviet Invasion of Afghanistan and the arming of the mujahideen. In order to combat the state atheism of the Soviet invading force, the united states with the help of Saudi Arabia arms and trains religious fighters in Afghanistan. Invoking the language of Jihad (Holy War) the mujahideen fight an extremely long protracted guerrilla war against the soviets. Some of these fighters will go and become the Taliban, setting the stage for the 21st century and the American "War on Terror"
All of these forces fought against Arab Secularism and brought religious Islam as a political force moving from the 1970s into today. To so answer the question, it's not that religiosity in Muslim countries has been a constant the whole time, but is a new phenomena that is directly tied to the geopolitical nature of the time and cannot be viewed a simply a religious matter.
Sources:
William Cleavland and Marvin Bunton "A Modern History of the Middle East"
Neamatollah Nojumi,"The Rise of the Taliban in Afganistan"
James Gelvin "The Israel-Palestine Conflict"
Robert Tignor "Modernization and British Colonial Rule in Egypt, 1882-1914"
I'd like to add on to the existing answers in this thread because I think there's a dimension that is completely overlooked. The perspective from Muslim intellectuals. I have studied the 18th century more than any other, so my answer will focus on this time-frame.
My answer is going to be rather surface level because I have never really studied the Christian reasons for secularism. From my understanding, the calls for secularism come from the control the Vatican, or the local churches exerced on knowledge. For example, the way Galileo, Copernicus and other scientists were deemed heretics and the books prohibited in the Index. I know there was widespread corruption in the Church organization as well, which caused some people to dislike the Church. This is roughly the extent of what I know about European secularism, but it is enough to explain why these issues were not the same in Islamic communities.
Islam's religious organization is rather decentralized, there is no equivalent to the Pope at least since the fall of the Rashidun Caliphate. This is important because it meant there was a lot of debates and different creeds within the same country. The Ottoman Empire, for example, despite instituting an official Hanafi legal code, allowed a multitude of Sufi orders as well as different school of thought. This whole dynamic is complex, but it essentially means that a citizen in Damascus, for example, was not strictly bound by what the Ottoman Empire considered to be the official creed. So even if the official creed would provoke discontent like the Vatican did, there were always alternatives.
Next is the fact that education is extremely important in Islam. Even the more conservative Islamic intellectuals agreed that withholding information to Muslims is forbidden. (There are some exceptions, as always) There was a debate surrounding Greek philosophy, but as far as I know it was never outright banned or considered heretical. People who were against Greek philosophy (or European technology) would still argue against them and explain why they serve no purpose and should not be studied, but studying Greek philosophy and European technology would still be allowed. There is no comparable to the persecution of Galileo and Copernicus and there is no Index in Islamic societies.
There was, however, a movement in the 18th century that sought to reform society and the Islamic intellectual world. Many people associate the 18th century with Muhammad Ibn Abd al-Wahhab, but he was very much an outlier. (See Dallal) The vast majority of the intellectuals of the time wanted to get rid of bad rulers and encourage more education, which I believe is similar to the secular movement in Europe. The Islamic intellectuals saw religion as an answer rather than an obstacle. There was an emphasis on critical thinking regarding the religion in the 18th century. The intellectuals would advocate for every Muslim to learn to read and form their own interpretation of Islam, if the people found a member of the ulama to be disingenuous then they had to disregard this ulama's opinion. (This is definitely not a universal opinion, but the majority of the intellectuals in the 18th century advocated for it) This was only allowed when the member of the ulama refused to prove his argument, so it could not be applied to honest judges and genuine intellectuals who provided their sources. People were thus encouraged to challenge the authority in an intellectual way, something that the Catholic church (as far as I know) opposed greatly.
Even today many Islamist organizations encourage education and will incorporate science within a religious framework. There are of course certain groups who discourage education, but those would be greatly frowned upon by the vast majority of Islamic intellectuals, regardless of their era.
This is very generalized and there are many differences between each regions, between each era and between each socio-economic classes.
In short, Islamic religious organization is very decentralized so there was no hegemonic power on religion and knowledge. Knowledge was usually encouraged in Islam. Religion was seen as an answer, rather than an obstacle in educating people as well as promoting critical thinking. The context of European secularism simply does not exist in Islamic history, religion was experienced rather differently so there was no need for Muslim to undergo what Europe did.
Edit: After reading the recent Meta post on the front page I felt the need to clarify that the reform movement in the 18th century encapsulated a vast part of the world where Muslims were a significant population. This includes West Africa, North Africa, India, Indonesia as well as Arabia. However, there were significant differences in each region (and even scholars of the same region had differences). I cannot express enough how much diversity there is in the Islamic intellectual world of the 18th century. (Dalal for these sources, but Azyumardi Azra has also written extensively about it for the SEA region.)
Sources:
Burak, Guy. The Second Formation of Islamic Law: The Hanafi School in the Early Modern Ottoman Empire. (2015)
Dallal, Ahmad. Islam Without Europe: Traditions of Reform in Eighteenth-Century Islamic Thought. (2018)
Hello! If you are a first-time visitor, welcome! This thread is trending high right now and getting a lot of attention, but it is important to remember those upvotes represent interest in the question itself, and it can often take time for a good answer to be written. The mission of /r/AskHistorians is to provide users with in-depth and comprehensive responses, and our rules are intended to facilitate that purpose. We remove comments which don't follow them for reasons including unfounded speculation, shallowness, and of course, inaccuracy.
This particular question has now reached the ouroboros moment: the overwhelming majority of removed comments are people asking why all the comments are removed. The second most frequent pattern among the removed comment are those that consist of a single word or sentence from people providing a personal anecdote or offering an observation on the question. So please, before you try your hand at posting, check out the rules, as we will not warn you further.
In other words, please do not post unless you can answer these four questions:
We know that it can be frustrating to see only [removed], but we thank you for your patience. If you want to be reminded to check back later, or simply find other great content to read while you wait, this thread provides a guide to a number of ways to do so.
Finally, while we always appreciate feedback, it is unfair to the OP to further derail this thread with META conversation, so if anyone has further questions or concerns, I would ask that they be directed to modmail. If you'd like to discuss the nature of this particular question, you're welcome to join the conversation in this META thread. Thank you!