It's because of something called photo-bleaching and it happens to the cells in your retina which is the light sensitive bit at the back of your eye. It's populated with cells called rods and cones, and these are full of light sensitive pigments.
Normally you get light as particles called photons coming into your eye; these stimulate the cells by changing this light sensitive pigment, which is called retinal, into a slightly different form and they stimulate the cells to send electrical impulses to your brain.
But, if you get a really bright light - like a flash or if you look at the sun for a long time or even just a really bright light bulb - this sends the cells into overdrive and they get really overexcited, and it takes them a little while to calm down. So then when you look at a normal level of light, like a wall, you get these kind of black spots where you've been looking at light where the cells have been over stimulated.