This chord progression is not strictly in one single key as we would understand in diatonic theory. It is used very frequently and is quite an ancient musical movement, which predates the emergence of modern music theory. It’s sometimes called the Andalusian Cadence and it does have an exotic quality due the major V chord. In a perfectly diatonic progression, we would expect that V chord to be minor if we were in a standard minor key.
Taking Am as an example, as long as you don’t land on the G from A minor pentatonic while the E major V chord is playing, you can use pentatonic all the way through. However, with a very small adjustment, you can add a very cool sound and flavour to your playing by landing either on the fifth of the V chord, in this instance B, or the third of the V chord, G#. That clash between the G# sharp in the chord and the G in the pentatonic is the reason it won’t sound good to play G over the last chord. The root of the V chord, E, is actually already in A minor pentatonic. Create phrases that mean you land on the E note, the B note or the G# note when you get to the E chord. Anything from A natural minor or A minor pentatonic will work over the rest. Compare the feeling and colour you get from landing on each of those different notes. E, as it’s in the scale already, will feel stable. B is pretty stable too and although it’s not in the pentatonic, it’s the note that is frequently added to the pentatonic from the dorian mode. G# may stick out much more because it’s not found in the scale and it’s not added in the same way that notes from Dorian sometimes are; and it’s the third note of the chord which typically draws more attention to itself. This can be a good thing: drama! High point of a lick or end of solo! Or – you may find it too much. There is no wrong answer – finding out what you like feeds into the development of your style.
Once you have applied this successfully in Am, try moving it to different keys. There’s a track in Dm below as well. Songs like Stray Cat Strut use the progression in Am before moving to Dm. Can you apply these ideas both in position (=staying around the fifth fret and switching to D m pentatonic) and in different positions? Once you can use and apply it in the first position in Am, you’ll notice that the respective 1,3,5 of the V chord are in the same place relative to first position pentatonic in any key – so, in Dm, if you’re playing at the tenth fret and the V chord is A, the C# note which is the third in the chord of A will be spaced at same points inside the pentatonic shape as the G# was in A minor. Which is a great time-saver!