Count up the key's own scale and the numbers name themselves. Every key grows from a major scale — seven notes built by one step recipe: whole·whole·half · whole·whole·whole·half (a whole step is 2 frets, a half step is 1). Start that recipe on D and you get D·E·F♯·G·A·B·C♯. Now just count: D is 1, E is 2, F♯ is 3, G is 4, A is 5 — A is 'the 5' in D for no deeper reason than that it's the fifth note of D's scale. Build a chord on each note using only the scale's own notes and the family appears: 1, 4 and 5 come out major; 2, 3 and 6 come out minor — which is why the sad cousin is always minor (the 7th one comes out odd; skip it for now). Change key and the recipe restarts from a new note: in G the fifth note is D, so now D is the 5. Same jobs, new address book.