Why is "great" pronounced as "grate", but spelled with "ea"?
Great is one of the few common English words in which "ea" is pronounced /eɪ/ (ay). Why is this pronunciation associated with this spelling?
As an aside, I remember from researching for my answer to a previous question that a Middle English spelling of great was grete. Was it ever pronounced that way?
First, I don't quite agree with this statement:
great is the only common English word in which "ea" is pronounced /eɪ/.
Break and steak are pretty common, and both have the /eɪ/ sound.
That aside, this goes back to the Great Vowel Shift, which is the cause of many of the peculiarities of English spelling. The linked Wikipedia article gives plenty of information, but the short version is that while most words with "ea" shifted to the /i/ sound, as in beak, some didn't, possibly because of the influence of the consonant following "ea". Great, break, and steak all have plosive consonants after the vowel; the "r" in bear and swear pulls the sound of "ea" in those words a different way.
And yes, I know, beak also has a plosive consonant, and fear ends in an "r". Changes in natural language are rarely consistent or easily explained, and this is one case where we just have to accept the fact that some words changed their pronunciation in a certain way and others, for whatever reasons, either stayed the same or changed in other ways. In other words, to quote Seth Lerer in his lectures on the History of English (2008):
As a coda to this lecture, let me mention a small group of words that seem not to have undergone the GVS. There are a small group of words that are spelled with -ea-, steak, great, break, and if these had participated in the GVS they would have been steek, greet, breek, and this is not something that affects every single word with an -ea-, it is not something which affects lots and lots of names spelled that way. But etymologically and historically, the words steak, great, break, should have participated in the GVS, and been pronounced steek, greet, breek. Why this is, nobody knows. So now I'm going to leave you with this provocation that even though linguists may think they can explain everything, there are gaps in our knowledge and exceptions to our rules.
As Nicholas mentioned, not only great but also break and steak have the correspondence "ea" = /eɪ/, and the reason for this is an irregular development during the Great Vowel Shift. These words had the vowel sound /ɛː/ in Middle English, which normally did turn into modern English /iː/ (the "ee" sound).
The linked handout comes from the website of the linguist Anthony Kroch; he attributes the development of the vowel in great and break to the initial Cr-cluster (which would tend to phonetically lower the vowel) and the final voiceless stop (which would tend to shorten the vowel and thereby emphasize the effect of the lowering). Kroch also mentions a number of words that show "ear" = /ɛə̯r/ such as bear, pear, tear (v), swear, wear. According to Kroch, pronunciations with /iː/ did exist for many of these words in the 18th century.
The Cr-cluster-and-voiceless-coda is not a perfect explanation for the development of great and break; Kroch gives other examples of words that have /iː/ in similar environments, such as breach and grease.
This specific explanation also doesn't quite cover steak, which has no Cr cluster, although it does end in a voiceless consonant (something that wasn't sufficient to shorten the vowels of words like beak or like).
However, it does seem likely that the preceding /r/, in the words that have it, had something to do with the sound change, for the phonetic reasons that were mentioned above (there is also one unique word that seems to show a similar irregular lack of GVS-raising for a back vowel after a Cr cluster: broad). Overall, it seems like the split of ME /ɛː/ to present-day /iː/ and /eɪ/ (not to mention /ɛ/, as in bread) was affected by a number of factors that interacted in complicated ways.
Something that it just occured to me might be relevant (I'd imagine it's been noted by someone else before) is that break, bear, swear, wear, tear (v) are all strong verbs that are conjugated similarly to one another in modern English (for example, all the past tense and past participle forms have o: broke(n), bore/born(e), swore/sworn, wore/worn, tore/torn). It seems likely to me that this is related to the similar development of the vowels in the present-tense forms of these verbs.
It seems like this has been an area of interest for a number of linguists who've studied the history of English—Kroch references Labov and Jespersen, so you may want to read some of their work if you're interested in learning more.
Incidentally, I have read (unfortunately I now forget where) that another word that shows the same phonological development, although it now has a different spelling, is drain. The Oxford English Dictionary says it comes from the Old English verb drēahnian, and that "The historical spelling is drean, pronounced in some dialects /dreːn/, in others /driːn/." This looks like it's parallel to great; however I don't know the details so the pronunciation with /eɪ/ might be due to something else (for example, I don't know if the vowel might have been affected in some dialects by the following "h" in the ancestral form of this word).