Although photons have no mass, they do have energy, and the gravity of a black hole (or any other gravitating body) will attract them. According to Einstein's theory of gravity, it is energy, not mass, that feels the gravitational force. That's the short answer