When we divide the octave into various equal steps using equal temperament, we find that there is a local maximum at 12, which yields a good approximations for important intervals.

But the "why" cannot be explained just using arithmetic. There is a history behind it. Twelve note instruments didn't begin with equal temperament.

There are twelve notes in western music because the diatonic scale has 7 notes, and alterations of these notes add five more, if you aren't picky about microtonal differences.

If you have do-re-mi-fa-so-la-ti-do, there is a small step between "mi-fa" and "ti-do" which is about half of the longer step that is observed in the five remaining successive pairs. If you identify some half-step note between those other pairs like "do-re" or "so-la", you end up with five more notes, giving you twelve. That's all it is; if we back fill 7 notes with enough notes to have chromatic half steps, we get 12.

Now, early practitioners of western music did know that that's not all there is to it: that a G# is not the same as an Ab. They tried using the in-between notes for transposing to other keys and found that the keys sounded different. They knew all about the mathematics behind it and the Pythagorean comma: that if you go around the circle of fifths 13 times, you don't end up at exactly the same note (modulo octave); there is a discrepancy.

Various technical devices were devised, such as splitting the small keys of keyboard instruments, so that the G# key actually had a G# split and an Ab split. Various tunings were also used, like well temperament. Bach's Well-Tempered Clavier is basically a set of test cases for tuning.

We settled on equal temperament because it distributes the error such that all the keys sound the same; when music is transposed to any key, the pitch relationships are preserved.

Going back to the first concept; why wouldn't more than five additional tones be added to add color to a seven tone scale? It's because Western music traditionally hadn't been oriented toward recognizing microtonal differences, or at least into organizing them (where they exist) into a single system.

In Indian music, there are 22 notes (shrutis). They are needed because there are numerous scales which have the same approximation on a western instrument. For instance, there are multiple scales that resemble "do-re-mi-fa-so-la-ti-do": the Pythagorean scale, but which use different microtones chosen from the 22 shrutis. Those scales all have different names; they are not just different tunings for obtaining different flavors of do-re-mi.

But in Indian music, there is still a significance in 12 tones in an octave!

"There are 12 universally identifiable notes ('Swaraprakar' in Sanskrit) in any Octave (Saptak). As we play them from one end on any string, the perception of each of these 12 changes 'only' at 22 points given by nature (See numbers in green in the slide below). The sounds produced at these 22 points are the '22 Shrutis' and the 3 types of distances in-between are called as 'Shrutyantara' (in Sanskrit) (See Legend below)" http://www.22shruti.com/

And: https://en.wikipedia.org/wiki/Shruti_(music)#Identification_...

It seems there is no getting away from the situation of there being identifiable 7 note scales (Swaras), into which we can stuff five more notes to obtain some kind of twelve-note chromatic scale.