The 3DS has two front mounted cameras that allow it to shoot stereoscopic images that replicate the way humans perceive depth when those images are viewed through a 3D display.
The 3D display on the 3DS uses a parallax barrier to replicate the perspective shift between the two cameras. In short, it displays both a "left eye" and a "right eye" image simultaneously, both of which are slightly skewed off the center point of the image being viewed. The closer an object is to the camera plane/lens, the greater the perceived effect. Conversely, objects that are far enough from the camera will show little to imperceptible perspective shift, effectively flattening the image (making it look 2D).
If you understand that, then you understand how the illusion of depth perception works and how 3D photos work.
Any device with two cameras spaced apart to approximate the distance between human eyes can shoot "3D" or stereoscopic images. Of course the other half of 3D photography comes in having a display that can show stereoscopic images which is why 3D images shot on the 3DS will only be viewable on the 3DS 3D screen until someone writes an application that allows those images to be exported and viewed on an external 3D display. It should be noted that the resolution of 3DS stereoscopic photos are extremely limited (640x480 max), meaning they would look either extremely cropped or extremely blurry on a 1080p 3D HDTV.







