When you close your eyes and suddenly see lightning it can be caused by Phosphenes which are moving visual sensations in your eyes.
Those visual sensations or Phosphenes are usually caused by electrical charges that your retina produces.
The electrical charges are produced by your retinas when the retinas are in the resting state and not taking in a lot of information such as light and other visual things that you can see.
When your eyes are open they are taking in lots of information when you're looking at things and the electrical charges are not as much as they are when your eyes are closed.
It can sometimes be normal to see lightning or flashes in your eyes when you close them.
Sometimes it may be caused by a more serious issue that should be checked out by an eye doctor as well.