Hi, I was wondering if there were any historical factors that explain why the west has become more secular/ less religiously affiliated compared to places like the Middle East. Has it got something to do with the religions themselves, or have certain historical events played a part.
Sorry if this question is too vague, if it is, message me and I'll try to rephrase it.
This is a big question but a lot of it boils down to what we think of today as "secular." I took a course in fall of 2015 in grad school on the history of Christianity and secularism so I think I'm somewhat qualified to answer this and will provide references where I can. Secularity is a messy term but the most common definition for it is that it is an epistemological category which is in some way irreligious. Secularity is not the same as secularism, which refers to a political doctrine that seeks to separate religious ideas and ideologies from public policy in the nation state, though the terms secularity and secularism often get confused in modern discourses (for a decent anthropology of "the secular" see Talal Asad's Formations of the Secular: Christianity, Islam, and Modernity, p. 1-2). It's important to note that before the late eighteenth century and indeed well after it, people in the west did not conceive of themselves as "religious." They understood that they belonged to a certain community like Christendom as was the case in the medieval period. They knew there were other communities such as the Islamic world after the seventh century but there was no conceptual space in peoples' minds of "secularity" or irreligion. Indeed the Roman pagans in late antiquity understood that the Christians were a discreet community but there was no such thing as someone who was "secular" and certainly not atheist or agnostic, which didn't come around until the late eighteenth century.
As an ideology, Secularism arose in Euro-America in the eighteenth century but came to fruition in the nineteenth and twentieth centuries out of the teachings of enlightenment philosophers like I. Kant, who promoted the use of natural reason and empirical observations of evidence to explain observable phenomena rather than resorting to scriptural authority (for more, see ch. 4 of Jeffrey Bloechl (ed.) Christianity and Secular Reason: Classical Themes and Modern Developments). Kant did not feel that religion or reason are competitors but instead they are related epistemological ways of thinking about principles and they have tensions with one another so he tried to separate them in order to make the scriptures appear more exceptional and appear less problematic when linked with natural reason. All this to say, Kant helped to lay the foundation for creating the very idea of "religion" as we understand it today (again, see the chapter in Bloechl). Religion, as an idea, came to refer to a collection of ideas regarding morality, social norms, and cultural customs for 18th and 19th thinkers.
We see competition in medieval and early modern high politics between secular jurisdictions (kings and emperors) and episcopal ones (popes and bishops) but these competitions are about who makes money off of land taxes. It's complicated by the problem that bishops were both episcopal (loyal to the pope and the clerical hierarchy) and also secular land owners (part of a king's retinue of land lords) for much of medieval history (see Thomas Brady "The Holy Roman Empire's Bishops on the Eve of the Reformation" in Robert Bast and Andrew Gow (eds.) Continuity and Change: The Harvest of Late Medieval and Reformation History, p. 21-2). To radically oversimplify due to time, secular lords became more influential throughout the early modern period (~1500-1800) on account of things like the Reformation which resulted in the break up of a common sense of identity in the west (although Christianity had never been fully unified on account of the east vs. west church split, the emergence of heretical groups like the French Cathars and Bohemian Hussites, and the rise of African and Asian sects of Christianity long before the Reformation). This increased disunity meant that people began to find greater unity in their national orders (i.e. England, France, Scotland, etc...). By the time of the American Revolution and their constitution, there were increased senses of nationhood within many western societies that were not directly related to their faiths. That said, America was the first country to consider itself purely "secular." However, today most Americans are still very religious with evangelical Protestants making up around 25% of the population so it's unclear how successful this secular enterprise really was (http://www.pewforum.org/religious-landscape-study/).
To come back to your original question, there's a lot going on here. Historical events have formed the contexts that make the rise of secularity and secularism in the west possible. The rise of European empires granted them a huge income of resources and wealth while the Muslim world was unable to keep up with the resource harvesting that Europeans were doing by the 18th, 19th, and 20th centuries. These resources helped individual nations forge their own national imagined communities irrespective of their religious identities (see Benedict Anderson's Imagined Communities: Reflections on the Origins and Spread of Nationalism, p. 11). In the Muslim world, the idea of the nation state did not really emerge until the 20th century and it's been a very rocky story ever since as these nations are still dealing with cultural tensions and turmoil within (just look at the situation in Syria right now). Many people in the Middle East derive their identity from their faith of Islam simply because nations don't mean the same thing to them as they do to us here in the west (for the most part).
I know I've talked a lot about the west here but it's important to note that both secularity and secularism are western constructions. It's not shocking that western liberal secular democracies, even though they claim to be secular and value free in terms of religion, don't often square well with other cultural norms. India is a hugely successful nation that is very secular in its constitution yet has had all sorts of trouble with religious violence and riots since it became independent in the 40s. Today if you're Jewish or Muslim in a country like the US you need to take your customary holidays off from work as a special case because they don't square well with the Christian calendar which makes life very easy for Christians to continue their customary norms even though they live in a "secular" country. Our daily work schedules also make prayer five times a day very challenging. Many secular folks find that people who express their faith openly are being "too in my face" even though there's no way to not wear a hijab for many Muslims. In short, secularism privileges certain groups who have historically been from western cultures (i.e. it's easy to keep your religion outside of other peoples' gaze if you're Anglo/German Protestant, not so easy if you have to pray five times per day).
In short, historical factors matter a lot. That's not to say that the scriptures have little part in this but 18th-century thinkers like Kant came to see ways of separating church from state and faith from reason following centuries of long and complicated debates and controversies surrounding these ideas. In the Muslim scriptures, there isn't that same level of tension between faith and reason as their scriptures don't make as big of a deal about it (Asad's Formations of the Secular, p.196-7). I'd say that the religions themselves have not been deterministic and that people have shaped the ideas to where we are now more than anything but this is a huge topic and hard to cover in a short post.
In a similar vein, when did this divergence first occur? In some ways the Ottoman Empire seems more "secular" than Europe was in, say, the 17th century (Europeans were engaging in very religiously-motivated conflicts like the 30 years war while the Ottomans were more or less tolerating many religions within their borders)