The way it works requires quite a bit of undergrad level knowledge. It can be explained by molecular orbital theory; the idea that when you put atoms together to form a molecule, their atomic orbitals overlap to make a set of new (molecular) orbitals.
The gist is that an electron absorbs the photon and is excited from one molecular orbital to a higher energy one. If this new molecular electron configuration is unstable enough (has a bond order of 0; effectively no bond), the molecule enters a 'dissociative state' and the bond breaks on the timescale of a molecular vibration.
The stronger the bond, the more energy the electron transition described above requires so the higher energy of photon is needed to break the bond. Cl2 and a lot of other molecules with weaker bonds have bond energies that correspond to the UV/Visible regions.
If you want to know more, you could have a quick look at molecular orbital theory, and the mechanism of the reaction you describe is photodissociation.