The pinhole magnifier works on a very simple principle: The closer you get to an object, the bigger it looks to you. This is because the closer you are to the object, the larger the image the object forms on your retina (click to enlarge the diagram below).
Unfortunately, however, there is a limit to this. If you get too close to the object, your eye is not able to bend some of the light rays enough to obtain a focused image. As a result, the image becomes blurry or fuzzy (click to enlarge diagram).
The pinhole magnifier gets around this problem by limiting the part of the eye's cornea and lens through which the light from the viewed object passes. Therefore, the light behaves more like light passing through the pinhole alone, and the eye's cornea and lens don't need to try to focus the image on the retina. The small aperture means the image is focused at any distance (click to enlarge diagram).
Sadly, there is a trade-off between the resolution, or sharpness, of an image and its brightness. A tiny pinhole produces a very sharp image, but, because it cuts down on the number of rays that enter your eye, the pinhole makes the object look much dimmer.