First, let's be clear that the standard (major) musical scale divides the octave into seven parts, not eight. The word "octave" comes from eight, because a unison (two notes sounding at the same frequency) is considered to be a "prime" or kind of a "one" in the system, rather than zero. Thus, the first interval created between a note and the next note above it is called a "second," even though it's only one interval.
This is just a historical convention for naming musical intervals, which sort of originated by counting both endpoints in an interval. For example, a musical "fifth" (frequency ratio 3:2) is the interval created by two notes that are four steps apart. So, C-D-E-F-G creates a fifth between C and G. The interval is five notes, but there are only four "steps" (of various sizes).
Anyhow, you need to get past that quirky numbering system first. So, I believe your question then becomes: why do we divide the octave into seven parts?
There are many longer answers here on this topic. But the gist is that like the octave (frequency ratio 2:1), small whole-number ratios of frequencies are often heard as "consonant." So the ratio 3:2 between frequencies sounds good (and, as noted, creates an interval called a perfect fifth), as well as the ratio 4:3 (the so-called perfect fourth).
The ancient Pythagoreans recognized the importance of these intervals (2:1 octave, 3:2 perfect fifth, and 4:3 perfect fourth). They also recognized that the difference between the size of the 3:2 and 4:3 ratios was useful, an interval with a frequency ratio of 9:8, which eventually became known as a "whole step."
So far, if you combine these ratios within one octave, you can build a perfect fifth and fourth up from the bottom note, as well as a perfect fifth and fourth down from the top note. The meet in the middle around a 9:8 "whole step." In musical notes, this would for example outline the notes E-A-B-E within an octave. (As I noted in comments, this overall can be thought of as a 12:9:8:6 ratio between four notes, which was how the Pythagoreans thought of it.)
Again, all of this dates to ancient Greece and is built on fundamental consonant intervals/ratios. The question then is how to fill out the rest of the notes within that octave. And the Greeks had a lot of answers to that, with a lot of different tuning systems.
But one possibility that they settled on was called a "diatonic" system, which literally means "through whole tones" (i.e., those 9:8 ratios I mentioned). They took that interval that originated as a difference between the 3:2 fifth and the 4:3 fourth and started tuning 9:8 "whole steps" to create a scale, starting at the top.
In musical terms, this was like going E-D-C down the scale. But they had already built B and A after that. So then once they got to A, they built more whole tones going down A-G-F. Then you had a complete scale going down an octave: E-D-C-B-A-G-F-E. Most of the intervals were those 9:8 "whole tones." But a couple (C-B and F-E) were smaller intervals with really odd mathematical ratios. In effect, the Greeks didn't care about those ratios so much: they just cared about tuning the other notes, and those left over small bits were kind of like the "errors" that were left over in tuning.
What you then have is seven intervals within an octave creating the diatonic scale, which survives to the present day.
As to how this relates to the 12-note chromatic scale -- well, some Greeks (particularly a guy named Aristoxenus) realized that those little left over bits in the scale were about the size of intervals that could almost divide the octave into 12 equal bits. They were a little bit off, though. Similarly, those little bits were roughly one half the size of the 9:8 whole tone interval.
Over the centuries once harmony developed more, there were various reasons that the 12-note chromatic equal division seemed to be better than the one constructed with the simple 3:2, 4:3, and 9:8 ratios. That's a much more complex story (the story of musical temperament).
But hopefully this explains the gist of why a 7-interval division of the "octave" developed historically.