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.