Here's the breakdown:
* 12 is the number of notes in a chromatic scale (all the notes in an octave).
* 7 represents the number of natural notes in a diatonic scale (the major and minor scales).
So, while not a perfect match, the number 12 is significantly related to the structure of a keyboard and its notes. This proximity, combined with the common slang use of numbers to represent things, could have led to "twelves" being used as a slang term for keys.
It's worth noting that this is just a plausible theory. There's no definitive documentation on the origin of the term.