Many melodies contain notes that are not from the scale they are composed in. For example, "Stairway to Heaven" solo contains an A minor pentatonic scale plus an additional F note. I've read that this is not uncommon. Does it mean it is still A minor pentatonic or not? Can playing notes not in a scale be done for compositions made using pentatonic scale or also heptatonic?
There's a common practice in Jazz and Blues to choose the scale based not on the piece as a whole, but just the chord that's currently playing. The ballad section is not totally in A-Minor either, but flirts with Dorian-Minor as well (the F♯ in the D-Major chord). The solo section of Stairway has these changes
You can play A-Minor (or A Minor Pentatonic) over the first measure because the G harmony functions like a seventh (so the A-Minor over the top feels like a suspension). But during the all-F measure, the solo voice really needs to make sense over F, so adding F (and landing on F) become useful to make the solo follow the changes.
As for playing notes outside the current scale, sure, why not? They're then called "non-scalar" tones. But if used too often (subjective, I think) then a non-scalar tone really becomes part of the scale. This is one of those "I know it when I hear it" things, and it's difficult to describe without reference to specific examples.
There are actually two things here. One: do you need to strictly stick to a key? To a prosriptivist, yes. That's what it means to "be in a key". Some theoreticians may disagree (but there are always factions).
Two: is "Stairway to Heaven" in A minor pentatonic or some variant? No. It is in A minor. However, common performance practices in jazz and blues involve soloing over a 6 note blues scale, similar to a pentatonic. Not having the sheet music in front of me, I cannot say for sure that this was what was performed, but I can make an educated guess (based upon Led Zeppelin's strong blues background) and bet that what I just described (soloing on the 6 note blues scale) is what was performed.
If you play notes which are outside of the scale and still call it "in the scale", you're really stretching the capabilities of the English preposition "in"! I believe there is room for staying in the scale while incorporating grace notes, glissandos or portamentos.
That F in the Stairway to Heaven solo can be regarded as shifting to another mode. Three major pentatonic modes (and their relative minors) occur in a given key. The solo does not stick to A minor pentatonic but uses modal runs within the A natural minor key (pentatonic and diatonic), plus blues microtonal bends.
It is not a solo in A minor pentatonic with out-of-scale digressions; that is hardy the concept.
The descending G E D C A G F run near the beginning of the solo is a blend of two modes. It starts as A minor pentatonic, but ends like an F major pentatonic. These overlap by four notes, so you don't know where one ends and the other begins; it is ambiguous. The F chord and bass note occur at around the beginning of the A G F phrase, so if a turning point between the two modes can be identified, that A might be the point where it occurs.
It is an effective twist which surprises the ear of the rock and roll listener who is used to hearing auto-pilot pentatonic noodling in one mode over similar progressions.
The F major pentatonic fits the underlying chord which is how modal improvisation works, at least some of the time.