There is a Seinfeld episode where George loses his glasses, yet he is able to spot a coin on the floor by squinting. Without knowing the team at Seinfeld made a very elegant scientific experiment comparing lenses to pin holes.
A Lens makes things sharp by focusing rays of light coming from a source so the rays converge on a single sport.
A pinhole, on the other hand, only allows light to enter from a single direction thus not letting it blur.
Both aspects are very clearly explained in this video by MinutePhysics.
Indecently, this video also explains how aperture works and why the Bokeh Masters Kit makes star shaped bokeh.
So why most applications prefer a lens over a pinhole (which is obliviously cheaper to manufacture?) Because pinholes work by blocking light the resulting image is significantly darker.