Oh boy. The answer to this question involves several thousand years of history, mathematics, philosophy, Church scandal, murder, warfare and utter chaos.
The short answer is that the modern eight-tone scales are artifacts of older tuning systems that did not give us the option of having twelve equally-spaced tones per octave.
Our tuning system goes back to Pythagoras, who was one of the earliest people in the Western world to write about harmony. Pythagoras noticed that strings whose lengths were whole-number ratios sounded pleasing together. In particular, he noticed the ratios 2:1 (what we now call an octave), 3:2 (a perfect fifth), 4:3 (a perfect fourth), and others. Pythagoras also realized that there was a big problem if you tried to construct complex harmonies across several octaves. Let’s say you tune your first note to 100Hz. An octave above that has a 2:1 ratio and is therefore 200Hz. The fifth has a 3:2 ratio, so it gets tuned to 150Hz. We really like fifths, so let’s tune a bunch of fifths above that. The next one up would be
(150 * 3/2) = 225Hz, then
(225 * 3/2) = 337.5, then
506.25,
759.375,
1139.0625,
1708.59375,
2562.890625,
3844.3359375,
5766.50390625
8649.755859375
12974.633789063
Now let’s go back and tune some octaves. We have 100, 200, 400, 800, 1600, 3200, 6400, and 12800. Notice how that last one is awfully close to our last fifth? 12800 is right next to 12974. If you’ve played piano for a while you probably know that 12 fifths should be exactly equivalent to seven octaves. But there is a slight difference. The two frequencies have a ratio of about 1.0136:1. A very ugly ratio, indeed, and extremely dissonant. To give you an example, a minor-second in the pythagorean system has a ratio of 16/15, or about 1.0666:1. But the difference we notice here is much smaller than even a minor second. This difference is called the Pythagorean comma.
The comma gives us all kinds of problems. We can’t play a bunch of octaves at the same time as we’re playing a bunch of fifths. Musical instruments, and by extension entire compositions, are limited in what they can do. The western major and minor scales consisting of eight tones between an octave are developed during the middle ages, but there is no standard frequency for the tonic. The ratios behave themselves as long as your composition does not get too adventurous.
All sorts of alternate tuning systems and instruments are invented during the middle ages and the Rennaissance. The Church regards the perfect whole number ratios as divine and any attempt to use anything else is obviously heresy. This annoyed composers who wanted to make more complex music.
Our modern notation system and the idea of the chromatic scale with sharps and flats is a vestigial product of this time, and we still use it even though there’s no reason to today. You can easily see that, depending on where you begin to calculate your ratios, C-sharp and D-flat were not actually the same thing. Instead, they were two notes separated by a tiny comma, and so could never be used together in the same composition. Our current system of key signatures reflects this; you either use C-sharp or D-flat, but never both, even though now they are the same.
So, the big discovery that gave us our modern, much more convenient system, is called equal temperament. This system abandons the perfect Pythagorean ratios, (except for the octave) and thoroughly pissed off the Church. To give an approximation of all the scales that were in common use in that period, a 12-tone equal-tempered scale was set up. This consists of twelve notes, spaced equally between an octave. To calculate the next note up, you multiply the first one by some constant. Since we want twelve steps to culminate in multiplying the first step by two, the constant we use is the twelfth root of two (about 1.059463). A 12-tone equal-tempered scale starting on 100Hz looks like this:
100Hz
105.9463
112.2461848369
118.920679725857
125.992060104395
133.483925974383
141.421280664598
149.830614276757
158.739992093495
168.179148243351
178.179584935345
188.774677594356
200
Notice that our perfect fifth isn’t so perfect anymore. Instead of exactly 150Hz, we get about 149.83Hz. This difference is so slight that most people agree it’s not even noticeable most of the time. And even if it is, the advantages of equal temperament outweight the slight dissonence.
And there’s no particular reason we have to use twelves tones, either. A 24-tone equal tempered scale can be easily constructed by using the 24th root of two instead.
So, to sum up: There are eight notes in a scale because there were eight commonly used Pythagorean ratios before we had equal temperament. This is of course why we call it an octave, even though there are twelve notes instead of eight in the entire thing. We didn’t get all those extra notes until all the various keys and tuning systems were folded into this big compromise system we use now.
Music is fun.