I'm gonna preface this by saying I am by no means a professional biologist, I am just a biology student who nerds out about art and biology sharing an interesting thought I had this morning.
We don't know where music comes from. That is the very disappointing answer I got to a very interesting question I had this morning. The best answer science can come up with is ...eh, it's kind of just an evolutionary hiccup that developed out of nowhere.
Hypothesis: Music isn't an evolutionary hiccup but actually an integral aspect to developing sapience.
Think about this: One of the very first things we'll hear as human beings both now as we're born and in the ages past when we first evolved is birdsong. We associate birdsong with two very important things:
Both of these give us a lot of valuable information like it is no longer dark, it is no longer cold, it is no longer dangerous, it is safe.
Early hominids with the ability to correctly identify birdsong and associate it with safety would thus be at great evolutionary advantage as they would be much more likely to survive the winter and the night, but that ability requires 3 major steps:
The ability to pick out distinct rhythms and melodies to correctly identify something as birdsong.
The ability to correlate said birdsong to the idea of the sun coming out.
The ability to make said connection through an abstract emotional response.
In other words, it requires pattern recognition, problem solving and complex emotion. Sapience. Music is not a coincidental fluke byproduct of sapience, it is the catalyst for developing sapience.
Granted this is largely speculation on my part; there's nothing I can do to prove that this is why our sapience evolved.
We are not the only sapient life on earth, there are others, some debated, some not. Besides us there are dolphins, whales, corvids, parrots and elephants, and do you know what we all have in common? We deliberately communicate through melodic and rhythmic sounds, and we derive a particular pleasure from doing so. We all enjoy music.
If music was an evolutionary fluke in our development, how come it's a commonality among all sapient life? There are many animals that sing to mate and sing to intimidate and yet they lack any signs of sapience, but the ones that sing just because they can all happen to be the most intelligent creatures on earth.