Sorry if this post gets confusing, its hard to write all this down in one post and not stray away too far from the question in hand.
There may be 12 notes in the system but in most scales theres only 7 notes (and in pentatonic theres only 5).
Music is art but its also math, the relationship between the root note and what you stack on top of it is mathematical.
If we for simplicities sake take the example of the C major scale (all the white keys) you have the notes C D E F G A B (and then back to C). The note names themselves isnt what makes up a major scale, its the relationship to the root note - this is called an interval. in any major scale the intervals are - root, major 2nd, major 3rd, perfect 4th, perfect 5th, major 6th and major 7th.
To construction any given 3 note chord in the scale you need a root note, a 3rd and a 5th. And to construct the chords you simply just take a note (C), take two steps up in the scale (E), and then two more (G). C E G is the I (1st chord) in C major and since its constructed of a root note, a major third (4 semitones) and a perfect fifth (7 semitones) you get a C major chord.
If we were to start on the second scale note D and do the same thing you would get D F A which would be Root - minor third (the F is only 3 semi tones from the root compare to the 4 semi notes between C and E in the previous chord) and perfect fifth (7 semitones) makin this chord a D minor chord.
same can be done with all the notes in the C major scale. and in the end you would end up with 7 chords in C major being:
I - C Major - C - E - G (root - major 3rd, perfect 5th)
ii - D Minor - D - F - A (root - minor 3rd - perfect 5th)
iii - E Minor - E - G - B (root - minor 3rd - perfect 5th)
IV - F Major - F - A - C (root - major 3rd - perfec 5th)
V - G Major - G - B - D (root - major 3rd, perfect 5th)
vi - A Minor A - C - E (root - minor 3rd - perfect 5th)
vii° - B Diminished B - D - F (root - minor 3rd, dimished 5th which is 6 semitones)
What about minor keys? its the same! the key of A minor shares the exact same notes as C major (all white keys) and the exact same chords but starting on the A.
Am, Bdim, C, Dm, Em, F, G.
Its all about the relationship to the tonic (first note of the scale, the "home" note). Music is about tensions and release and it all relates to what feels like "home", which is often your one chord. The home chord in C major its C and in A minor its Amin.
So to sum this up scales and keys are the framework and "rules" for which music is built upon. Sure music is subjective and all but to break the rules i believe you first need to know them.
feel free to ask for clarifications and keep jammin.