It's easy. Let us consider a water with a plane wave on its surface. Without any obstacle on the surface this wave propagates without changing. If there is an obstacle (a rock), the wave scatters of it. If the wave is sufficiently energetic, it can create two bubles on the surface attracting each other.
The same is with photon. While scattering off some obstacle (a nucleus), it can create an electron-positron pair (a neutral system - the total charge should be conserved!). The necessary condition for that is hf > 2mc2.
Another analogy/phenomenon is atom ionization. A photon can "break" the nucleus-electron attraction and create an electron and an ion (photo-ionization). The necessary condition for that is hf > I, where I is the atom ionization energy.