Listen to the rhythm guitar if you're having trouble understanding where the leads are coming from.
Take Yesterdays for example. The chords behind the solo start off with Bm G Bm G, which is where the Bm pentatonic scale is used. The next part of the solo goes Bm C#m Dmajor Emajor, which finishes off the solo before dropping back down to Dmajor for the start of another verse.
Now essentially, the solo segment is in the key of Bminor, but when you bring chords in that aren't naturally part of that key i.e. C#minor and Emajor (the main chords one would naturally associate with the key of B minor are B minor , D major, E minor, F#minor, G major, A major), then you need to alter the scale you're playing your solo in to accommodate the change of key in the rhythm.
You'll notice that this seemingly stray G# note that appears in the solo is played only over the Emajor chord at the end of the solo (Slash plays the same little 3-note rake that he plays in the Don't Cry solo as well). As Oddy said, the G# note is part of the E major scale, so it works perfectly over an E major chord. During this held Emajor chord Slash flits between the Emajor scale and Eminor pentatonic, before resolving the solo in a D, just when the rhythm guitar changes back to the key of D for the next verse.
The same theory applies at points of SCOM. During the slow part of the solo, the sustained Eb notes are only ever played while Izzy plays a B7 chord in the rhythm.
It's very easy to get hung up on this kind of thing, asking about the theory behind each individual note. Don't worry about it too much, with practice and experience you'll develop instinctive "rules" about what you can and can't do within the context of a song. My advice definitely is to listen closely to the rhythm guitar first before trying to understand the solo - listen out for the obvious key changes and take it from there
Good Luck