1. The beat of music is a regularly repeating pulse. Whereas the pulse is an accentuated piece of the music such as a kick drum, note change, etc. By extension, this means that there requires more power to produce those pulses. Now as to why the headlights dim: I'm going to rely on the assumption that they are standard halogen lights.
A. Without going excessively far into wavelength emittance along the visible spectrum, or changes in resistivity over heat; A halogen light is a heating element - a resistor. The power this draws from the electrical system can be calculated by v^2/r, where v is the voltage at the headlight, and r is the resistance of the headlight.
B. Everything has resistance. Wiring, battery, will all have voltage drop through them as a result of current demand and resistance. Then you have the differential between charge voltage of the alternator and the resting voltage at the battery when it will begin converting chemical energy to electrical. Add to that there's a response time in the alternator between when the voltage changes from its set point, then the regulator changes the power going to the rotor.
So what this all means, is if you have a sharp change in power requirements, you get a change in voltage of the system of your vehicle. Each beat, or pulse in the music, will cause this. You can also see the effect if you roll your window up/down then toggle the switch while the window is at the limit of its travel
2. Bearing in mind the info from 1. There are 2 ways you can eliminate this dimming issue
1. Use a headlight that has its own power supply that will provide a stable output independent of the input. An LED or HID would work in this scenario
2. Rig up a capacitor and a diode at the headlight such that the effect of these temporary voltage dips are mitigated such that any dimming that occurs isn't visible to the eye any more