Unlike many modern devices with backlights, the brightness levels for the Nintendo 3DS, 3DS XL and 2DS do not automatically adjust to the ambient light. They must be adjusted manually.
Don't forget that even in the middle of the game you can go to the Home menu and adjust the brightness.