If you are playing the blues in the key of C, any note in the blues key of C should sound good in the melody with either of the C, F or G (I, IV or V) major chords in the bass.
Why is this and how do these three chords relate to each other?
The three chords you have identified are known as the Tonic (I), Subdominant (IV), and Dominant chords of the traditional major scale. By in large for over 300 years the IV and V chords have been used extensively in western music to reinforce the tonality of the tonic.
This is accomplished by the resolution of tension created by dissonance. The V to I transition is the strongest feeling of resolution as the 7th degree of the scale and 2nd degree of the scale converge to the tonic.
The blues scale is sometimes referred to as minor pentatonic scale or an altered major scale with lowered third, fifth, and seventh degrees. The transient use of the "blue note" (flat fifth or sharp forth) is highly characteristic of blues music. This note relative to the tonic, is also known as a tritone, or in sacred music, the 'devil's note' which was avoided in that idiom. In any case the blues scale in practice is dynamic, it changes all the time, often a major 3rd scale degree in the scale is altered to a minor 3rd scale degree or the reverse, sometimes within the same melodic line. A slick blues lead might embellish any scale degree with repeated grace notes of a semi tone above the scale degree or below it depending if the line is ascending or descending.
Often the chords you identified are played with 7ths which adds more dissonance and allows for more tension. Typically in a blues song a tonic chord played with a 7th would be constructed with these scale degrees: 1, maj 3rd, 5th, flat 7th, or in the key of C this would be C, E, G, Bb. Likewise the subdominant and dominant chords are constructed with the same relationships. Subdominant in the key of C: F, A, C, Eb. Dominant: G, B, D, F. Now what may change in these chords are the 3rds, and 7ths. The changes along with the use of embellishments such as heavy use of sliding extended grace notes back and forth, or repetition of tritone relationships, glissandos (keyboards and guitars), bending notes (guitar), even literally banging the keyboard and other innovations shape the blues idiom.
Summary: The tonic, subdominant and dominant chords in the Blues scale have a tradition in classical music that best supports tonality. Altering the 3rd, 5th and 7th scale degrees in these chords creates a platform to allow the melodic line to be more flexible and use more notes.
I think it's because they really DON'T fit any. They just have their own inherent sense of the tonality of the tonic, while the chords - sprung from the same tonic but in a different mode - guide themselves in and out of dominant relationships, for example bar 4 makes the I chord the dominant for the 5th bar with the IV chord, even though it has been dominant all the time.
The blues scale contain all the chord tonics though and the rest of the scale is putting dissonance to the chords. E-flat; is dissonant to E in C7, F-sharp; is dissonant to G in C7, F and G in G7 and B-flat is dissonant to B in G7.
There is really nothing theoretical about the blues scale it's a tradition inherited by the slaves that used to bend their guitars a bit to play the notes in between the 12 notes.
Another thing to keep in mind when playing the blues, which is unlike a lot of rock 'n roll, is that you have to follow the changes. It's more like jazz. That's why a lot of rock players who can rip pretty good on a pentatonic scale don't sound good playing over a I - IV - V progression. Staying in the pentatonic minor scale of the tonic (I chord) doesn't sound so hot when the IV and V chord come around. And moving the pentatonic minor scale to follow the changes in a blues doesn't work either! The other post notes that if you analyze the I - IV - V chords in a blues, they're frequently I7, IV7, and V7. That's why a pent minor doesn't work. A dominant 7th chord has a major third. Many blues progressions use minor chords, of course... depends on the song. The Allman's "Stormy Monday" is an example of a minor 7th blues. David Lindley's "Mercury Blues" is an example of a more major, Dom 7th-based blues
So here are a few things that work, formulas to help you navigate if you're not Stevie Ray Vaughan. (And we all know there was only one of him!)
If you know your chords and you can play dominant seventh arpeggios, following the changes doing those works pretty darn well. If you are able switch them on the fly to min 7th arpeggios and create that funky tension, then you've got a formidable toolset right there. If you know a little more and can play both the major and relative minor (or vice versa) arpeggio associated with the change, then a world of possibilities will start to explode.
There's no one "secret" to anything in rock and blues music, it's as much intuition and talent as knowledge, but if anything comes close it's knowing your way around the mixolydian mode. The mixolydian mode is a major scale where you start and end on the 5th of the scale. What it amounts to is a major scale but with a b7th. (7th scale degree played a half-step down.) Because so many rock and blues songs that tend toward major keys are not really "strict" major, meaning solos using a major scale with a raised 7th don't "work", the mixolydian mode will have you smiling and going "A-HA!!!" when you hear how well it fits when playing over "more or less" major rock and blues songs. I say "more or less major" because anyone who plays rock and blues knows that the lines (as the other posts here iterate as well) between minor and major are blurred. And once you know the mixolydian scale well enough, you can "convert" it to minor by flatting the 3rd. At that point you're actually playing the "melodic minor" scale (natural minor w/raised 6th). If you can play mixolydian and "minor mixolydian" then you can SHRED the blues and you will sound totally professional.
I'm not really a "scale" player, meaning I never cut my teeth like a jazzer learning all the modes and following fast changes and stuff. I do not solo well over a fast harmonic rhythm. (chords that change frequently and quickly) So I need tricks that apply to broad applications. Arpeggios, pentatonic Maj and min, harmonic minor and mixolydian have taken me really far!
The mixolydian mode sounds really good when you move it around and follow the changes in a 12 bar blues.
Last time I tried I could not post an attachment but I'll try to put up a PDF of a common pattern I think of when I play mixolydian. I think of it as almost the same fingering as the natural minor scale, but I slide the first finger up a whole step going from the first scale degree to the second, and then it's a normal pattern for a minor scale.