Most are time exposures. You set up when a thunderstorm is known to be approaching with your camera on a tripod. When you see generally where the lightning is coming from and where it is striking, you point the camera and then use the "B" or "bulb" setting which opens the shutter and keeps it open until you close it.
Or you cab set your camera to a very long exposure like several seconds. If the lightning doesn't strike while the shutter is open, you keep trying. Eventually you get a decent shot.
A similar method can be used for fireworks.