A Theory for the Variation of Dust Attenuation Laws in Galaxies