Many melodies contain notes that are not from scale they are composed in. For example, "Stairway 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.