They are caused by the mechanical stimulation of the cells in your retina, which is the light-sensitive layer at the back of your eye. When you rub your eyes, you are pressing on these cells, and this triggers them to send signals to your brain, which interprets them as light.
So, the "stars" are not actually stars, but rather the result of your brain responding to the pressure on your retina.