One derivation starts with E = mc^2, which is a special case of E^2 = m^2c^4 + p^2c^2 but with velocity set to zero. In the second equation if you instead set the mass to zero you get p = E/c (momentum equals energy divided by the speed of light) for massless particles.
The deeper reasons are above my pay-grade.