The G major triad uses pitches that appear in both the C harmonic minor scale and the C melodic minor scale, namely G, B, and D. In fact, the tendency to use a major triad on the fifth degree of the scale predates by a few centuries the idea that there are multiple forms of the minor scale, and the tendency to raise the seventh degree (B flat to B natural in C minor) predates the development of harmonic theory by a few more centuries.
The multiple forms of minor scales were invented in the 19th century to reconcile the many different chords that can appear in minor keys (for example, that pieces in C minor frequently have F major and G major chords as well as F minor or G minor). Trying to determine what chords are "allowed" by various scales is more or less what my grandfather liked to call "bass ackward."
Each of these 4 chords has to be modified with natural symbols to fit in the key signature so it surprises me that they should be there.
The same is true of the harmonic and melodic minor scales. This is one clue that scale is not the same as key. Similarly, pieces in C major also frequently contain D major chords or C7 chords, which require chromatic alteration. This has its roots in the phenomenon of the secondary dominant, as Tim notes in his answer, but nowadays they can arise for other reasons as well.
In a comment, you say
I'm looking for a rule (I live by algorithms) why A♮ and B♮ are not in the key of Cm and yet those 4 chords I singled out are part of the Cm family of chords!?
Here you go:
- A cadence has a target pitch. This is most commonly the tonic pitch of the key (e.g. C in C minor).
- The standard cadence approaches the target pitch from the pitch immediately above the target pitch (e.g. D-C in C minor).
- The second voice in a standard cadence approaches the target pitch from the pitch immediately below (e.g. B♭-C in C minor).
- Immediately before reaching the target pitch, the two voices should be separated by a minor third or major sixth. If the diatonic pitches surrounding the target pitch are separated by a major third, raise the lower pitch (or, less commonly, lower the upper pitch) by a half step (e.g. B♭ becomes B♮).
- If the previous operation results in a melodic augmented second in one of the parts (e.g. A♭-B♮), alter the previous note to make it a major second (e.g. A♮-B♮).
This is more or less the standard explanation for the existence of the harmonic minor and melodic minor scales. These scales are part and parcel of minor-key tonality.
In the late middle ages and the Renaissance, these rules led to the development of something called musica ficta or "false music." That's because the raised leading tone (e.g. the B♮ in C minor) was frequently outside the set of "allowed" notes. In time, however, the raised leading tone came to be considered an integral part of minor-key tonality. By that time, around 1600, the rules above had evolved into something like this:
- A cadence has a target pitch. This is most commonly the tonic pitch of the key (e.g. C in C minor).
- The bass part in a standard cadence approaches the target pitch from the pitch a perfect fifth above (or a perfect fourth below; e.g. G-C in C minor).
- The next-to-last chord in a standard cadence has a major third (e.g. B♮ in C minor).
In your question you write
Add to this, the "Bdim" as an allowable chord for the 'harmonic' Cm scale.
And finally, add to this, the "Bdim" and "Adim" chords as allowable for the 'melodic' Cm scale.
The problem with this reasoning is that you're only using the "extra" notes that you get from chromatic alteration (that is, the extra notes that you get from including the harmonic and melodic minor scales) as roots of chords. But they can also be used in other positions. So, in C minor, A♮ can also appear as the fifth of a D minor chord or the third of an F major chord. With B♮, not only can it appear as the third of a G major chord, but using B♮ as the third of a G major chord in C minor is precisely why we have the harmonic and melodic minor scales!