So this ultimately goes back to the ancient Greeks, but really the last days of the Roman Empire.
Ancient Greeks drew a clear distinction between themselves and the Iranians, who were to the east. Hence "the East" was seen in Greece as uncouth, aggressive, and imperialist, in contrast to rational, honourable Greece. The Romans, who also didn't get along with Iran, adopted the Greek idea and spread it around Europe. (And they all looked down on the Arabs, who the Greeks sort of lumped in with the Iranians).
But this separation wasn't particularly a thing for the late ancient or entire medieval worlds; if people were aware of other lands, they mostly didn't divide the world into East and West. No, the concept of a division came right at the start of the early modern era, when the Eastern Roman Empire, who identified with the Greeks as well as the Romans, was conquered by Ottoman Türkiye. Ethnic Greeks found references to the barbaric East in ancient sources and revived the idea of "the East" as evil, in contrast to the civilised "West" (ignoring the fact that the Iranians and Turks were plenty civilised, and the uncivilised Mongols had wrecked the shit of every civilisation they came across). Turks were perceived as bizarre, Satanic foreign invaders; Türkiye was also a highly-centralised multicultural state, while the rest of Europe was a patchwork of non-state peoples held together by custom and oaths. Türkiye was thus also seen as exotic and Other. Early modern Christians also attached these traits to Islam as a whole, as they initially were not really away of other Muslim cultures.
A couple of notes. Ottoman Türkiye spanned Europe and Asia, but was culturally a very European country, especially in the 15th century, when the above events went down. The sultans were more concerned with Rumelia than Anatolia; they thought positively of Europeans while heaoing scorn on Arabs, Armenians, and Kurds; and the Ottoman court was utterly dominated by Christian converts to Islam from the Balkans (which was an official policy). See The Ottomans: Khans, Caesars, Caliphs by Marc David Baer for an extensive exploration of this, and also a sweeping look at all that was glorious and terrible about Ottoman Türkiye. You, the person reading this, should absolutely read that book.
Also, no medieval Europe did not have countries, with the possible exception of the Eastern Roman Empire. Peasants gave part of their labour to a local minor lord, who would swear allegiance to a bigger lord, who swore allegiance to a still higher lord, and so on up to the king, but the king only directly controlled a relatively small area of land. The king had no direct authority over the lands of the lesser nobility, who owned those lands; custom and their respective oaths of allegiance, rather than law, dictated that people obeyed the king, and conversely, the king could only push his subjects around so much before they rebelled. Historian Bret Devereaux talks qutie a bit about how medieval Europe actually worked; there is a series here, comparing A Song of Ice and Fire to real history, and another one here, which uses a playthrough of Crusader Kings III to talk about medieval politics. Again, worth reading, though there is quite a lot.
A point that neither Baer nor Devereaux ever make, but can be inferred by reading both, is that the centralisation of power and increasing power and euthority of kings in central and western Europe was the Turks, with their highly-centralised government and powerful sultan, winning quite often, and so the Christian powers gradually became more Turkish. There were real concerns that Catholicism and nascent Protestantism would be conquered and subsumed by Islam.
But anyway! Early modern European Christians drew a distinction between themselves as the Muslim Turks (though before Süleiman the Magnificent became caliph, the majority of the sultan's subjects were also Christian). Thus, "The West" was Christian, and they identified as the heirs of Greece and Rome. "The East" was Muslim/Turkish (though Baer argues that Türkiye had a far better claim to be the inheritors of Rome and Germany (the "Holy Roman Empire") or Russia (the "Third Rome")). There were real fears that Catholicism and nascent Protestantism would be conquered and subsumed by Islam; at best, they would be made subject to a Muslim autocrat, as had already happened to the Greek Orthodox Church. There was some real complexity and nuance here; Holy Roman Emperor Charles V was so unpopular he was derided as the "baptised Turk" (Süleiman was the unbaptised Turk), and Pope Clement VII declared it would be a positive devel