Sunlight bleaches things. I’m not sure I understand exactly why, but it’s to do with the high energy from the sunlight doing something to the chemicals that give colour and making them colourless (as you can tell, I REALLY don’t know much about this kind of thing!). But anyway, hair is just like other coloured substances, it gets bleached by sunlight so your hair looks lighter.
I know that sunlight has a bleaching effect on lots of coloured things, like if you leave a picture or some clothes in the sun the colour will fade. So, I assume that the sun bleaches the colour out of it.