Your brain requires an obnoxious amount of energy in order to function, and that energy demand is not static.

Intense thought can double your brains metabolic activity, and in order to keep up with that, your brain needs more blood. Your heart has to work harder, and the blood vessels connecting your brain to to your heart have to work well; once the blood reaches your brain, it has to be distributed appropriately to make sure all areas with increased activity are adequately supplied. This might require building new vessels, or expanding existing vessels. Excising can kick that process into high gear.Basically all of your body may be demanding more blood during intense exercise, but if your brain doesn't get enough you die, so it adapts. Those plumbing upgrades don't just go away when you aren't exercising. If you are just sitting in class and thinking, your brain has more food to play with, and you can think clearer.

Sports usually inspire a degree of self discipline as well, and can help motivate success through peer pressure, or reward. Taken together, physical sports can help develop your brain to function better, and give you the mental desire to function better. Depending on the sport, it also provides practice at multitasking/coordinating different motions/senses, or problem-solving depending on the game.

There is some interesting research on the effect of FPS video games on problem solving and academic function if you want to learn more on that angle. I imagine with music, it's similar, but I don't study Neuroscience, so I would be guessing about the brain areas affected.