History of Music Theory

Music theory's earliest roots go back to ancient Greece, where Pythagoras is credited with discovering that pleasing musical intervals correspond to simple mathematical ratios between string lengths. Medieval church musicians built on that with the modal system used in chant, and by the Baroque era, the age of Bach, the harmony and key system that still underpins most Western music today had been largely codified.
Notation itself went through its own long evolution alongside the theory, from early neumes (rough pitch-direction marks) to the fully specified staff notation used today. It was a system that made it possible for the first time to write a piece of music down precisely enough that a musician anywhere could read and perform it accurately without ever hearing the composer play it.
What's taught as 'music theory' in a classroom is really that few-centuries-old system, formalized into the grade exams and syllabi used worldwide now. Because the same underlying harmony applies across virtually every instrument, theory training is one of the few things that transfers directly, no matter which instrument a student ends up specializing in.