Normally, light is emitted from each point on an emitter in many directions at once, subject to any optics present. When shining on a suitable small pinhole, essentially only one beam from each point on the emitter is being passed through the pinhole to shine on the opposing wall. So what you are seeing is the relative light values of each point on the emitter - an image of the emitter-since the individual values are not being washed out by rays from adjacent points, as they are in a normal beam.
As an example: Say I have an emitter that has three pinhead elements. Each pinhead is emitting photons in all directions, but only the one or two (or three, or ...) traveling directly toward the pinhole will pass through to strike the opposing wall. The same with the other to pinhead emitters. So what I wind up with is three faint images of the pinheads, as if by magic. This is the same principle used by a 'pinhome camera' to take a picture without a lens. It is depending on the particle aspect of light, as opposed to the wave aspect., and that is as far as I am going to dive into the dual nature of light.