Your eyes are so used to not wearing sunglasses that when you do wear them, your eyes feel weird. They are not used to being shaded, so you may get headaches the first couple of times you wear them. It doesn't mean the sunglasses are bad, although sometimes, knock-off sunglasses will harm your eyes because they are not of good quality.
Because of the shade vs. light, you may not notice that you are squinting your eyes to see through the shade. You are used to seeing all that sunlight and your eyes have adjusted to that. Your pupils have to dilate some to adjust accordingly to the level of the shade. This doesn't seem to make much sense, because the initial thought is that your eyes would be squinting to help protect them from the immense sunlight. While this is true, so is the opposite for those who might have more trouble seeing through "darkness" or shade, in this case. The squinting causes strain and tension which will in turn cause a headache.
Also, the sunglasses may not make the world you see through them as clear (match up with the power of your vision) and thus cause you to squint. You may not notice this squinting either.
Should your headaches continue, try out a variety of sunglasses. If none seem to make it better, consult an eye doctor. They can offer prescription sunglasses. It could be something as simple as the brand of sunglasses (quality) or something more complex like the dilation of your pupils, etc.