The shift of the short
[a] from /a/ -> /æ/ between Middle English and Early Modern English (EME) happened across England except for the north. Dialects sometimes vary from standardized explanations of vowel shifts. /trap/ would be most common in the north, /træp/ would be most common in the south, the Midlands would have both, and exceptions would exist everywhere.
For this answer I consulted two sources in-depth:
A personal note: I've also learned and taught pronunciation of Middle English and EME literary texts up to John Milton and Margaret Cavendish (mid-1660s). When I teach pronunciation, beginner's instruction focuses on a standardized explanation of long vowels pre- and post-vowel shift. Intermediate instruction will raise a couple of other points, like major regional differences where a text requires it. (The Scottish poet Robert Henryson sounds different compared to the London-based poet Geoffrey Chaucer.) I make sure students know that general phonetic models are inexact approximations that don't account for fine distinctions and dialects. Still, the standard models for pronunciation are useful as a baseline for learning and comparison, and I'm indebted to the linguists and language scholars who devised them.
In standard EME, /æ/ became the primary short-a vowel instead of /a/. Minkova illustrates the general shift in vowel pronunciation in two charts on pages 200 and 238:
You described it odd that vowels would shift from /a/ -> /æ/ and then back to /a/ (or even /ɑ/ in some dialects). Minkova maps the vowel shifts from Old English to the present to illustrate that the short-a started as /æ/, moved to be primarily /a/ but sometimes /æ/ in Middle English, switched to be primarily /æ/ but sometimes /a/ in Early Modern English, and is currently /æ/ in standard English with common variations shown in the second chart. The history of this vowel shift could well be called There and Back Again, and this pattern held especially true for southern and midlands varieties of English. /træp/ was dominant and /trap/ was possible.
The more recent shift in some southern dialects and RP to move back to /a/ or even /ɑː/ is hard to relate to any single cause. Terttu Nevalainen explains the creation of the resulting trap-bath split (/a/ or /æ/ in trap and /ɑ:/ or /a/ in bath - basically, the vowel in bath is moved further back than the vowel in trap) as a more recent shift in pronunciation that follows the EME period. For Nevalainen, /træp/ was still the conventional EME pronunciation:
The Middle English high vowel /i/ in bit and ship was typically realised as [ɪ] in Early Modern English, the same as today – but / ε / and /a/ were raised. The low-mid / ε / ( bed , set ) moved up leaving room for /a/ to raise to /æ/ by the mid-seventeenth century. This is when words like hat , man and trap gained the pronunciation they have today. The number of words included in this /æ/ set was, however, much larger in the Early Modern period than in RP and southern British English dialects today. It contained bath , castle , glass , last , master , pass , path and many other words with similar sound patterns. The set split when the vowel in these words was lengthened in the south in the course of the seventeenth century and backed to / ɑ / in Late Modern English. There was fluctuation in various subgroups but most of these changes did not take place in the north of England or in American English, which have retained the front vowel in both trap and path words. (pp. 124-5)
What about the big exception at the center to your question? While Nevalainen suggests that "trap" and "path" "retained the front vowel" in northern varieties of English, that
[a] vowel is probably much like in Middle English: most commonly a mid-front /a/ and sometimes the front /æ/. In other words /a/ remained more common than /æ/ in use through the early modern period in northern England. As for the variation in that explanation, Minkova acknowledges the tremendous regional and even local variety in how this vowel was realized, to the point that the coexistence of these two vowel sounds goes all the way back to Old English:
The low front vowel is extremely susceptible to contextual, regional and social variability, so for ‘generic’ ME /a/ it is reasonable to reconstruct realisations ranging from a higher [æ] to a retracted realisation [ɑ], the latter most likely to occur before liquid codas, as in stark(e) ‘stark’, warnen ‘warn’, barbour ‘barber’, salven ‘to annoint’. The relevance of this to a PDE speaker is that the coexistence of [a] and [æ] as non-contrastive realisations of the same phoneme can be projected all the way back to OE. (p. 200).
The last sentence means roughly that if you were to enter England in 2019 or 1719 and say /trap/ in London or /træp/ in York, you might get a funny look but you'll still be understood. You might even find someone who grew up in that place whose individual pronunciation isn't too far away from yours.