Hold the device away from your face. The light or lack of central focus may be bothering your brain. Consider purchasing blue-light filtering glasses.
It may also help to not play in dark environments. With the 3DS shining in your face, it could be multiplying the aforementioned light issue. Eye strain and headaches are a result.
Make sure 3D is off. This causes headaches for some people, especially if they are not properly distanced away or have it maxed.
The problem might not even be the 3DS itself, but the way you play it. Do not lay down as blood would accumulate in your head and cause headaches. Sit in an upright position like you just ate food.
If you still encounter headaches, you may want to consult a doctor as it could be a much more serious condition. It is not normal for users to experience headaches from simple usage.
Good luck.