We're gonna keep it simple. Let's say we're in G major. We want a simple I-IV-V chord progression which, in G, is G, C, and D (all major, of course). To solo, we will use the G major scale.
Now this next part will be internalized over time, and you won't even have to think about it. But at first, it will help to break things down. The key of G major contains the notes GABCDE and F#, and the G major scale is GABCDEF#G. These are the notes we want to stick to for the most part. But just playing them mostly at random over the progression isn't likely to turn out something outstanding.
We next need to look at the notes in each chord of the progression. They are: GBD for G, CEG for C, and DF#A for D. Here's where consonance and dissonance come in. The notes in each chord are consonant for that chord, and all other notes are dissonant. Consonant means that it sounds very nice and relaxed over the chord, while dissonant means that there is some level of tension. Every note not in the chord, whether they are in the key or not, has some level of dissonance.
I'm certainly not saying that the only note you can play over a G major chord are G, B, and D. What makes great solos is how they manipulate this dissonance to create and resolve tension. And this is the sort of thing you want to pay attention to when analyzing music.
So to make your solo really lock into and fit the progression, try starting your phrases on consonant notes. When the progression changes to the next chord, play a note that's consonant with that new chord and continue your phrase. This sort of thing will really make your solo part of the overall song.