Why does a pinhole create an image of the Sun? When I was a kid I happened to encounter a solar eclipse. I was taught that I should not look at the Sun directly when it is undergoing an eclipse, but I was extremely curious to see it. 
Somebody suggested to me that if I created a pinhole in cardboard and place the cardboard in the Sun and managed to get the light passing through the pinhole on a screen inside the room then I could see the eclipse on the screen. I did that and I could see the eclipse on the screen.  
My question is, why was I not seeing a circular illumination on the screen? But to my surprise, as the eclipse was progressing on the Sun, the illumination I saw on the screen was also undergoing the same eclipse! It means the illumination on the screen was the image of the Sun! 
Why was it not a uniformly illuminated circular patch on the screen? Why was it undergoing an eclipse? The light was passing through all the portions of the hole, so why was an eclipse showing on the screen? 
In summary, how does a pinhole create an image of the Sun? And not always a circular illumination? 
Edit1: If we place a single point source of light in front of the pinhole then it creates a circular illumination on the screen, but if we put an extended object in front of the pinhole then it creates an inverted image of the object on the screen, how? An extended object can also be considered as a collection of infinite point sources of light. If one source produces a circular patch then infinite sources should also produce the same circular patch, just of greater intensity. The shape of the patch should not change. Why does the shape of the patch change to the shape of the object on the screen? 
Kindly help. 
 A: this effect is called the pinhole camera, it functions as follows:
The sun is an extended object, every point of which is radiating light. If we send that light through a tiny aperture, then from each point on the sun only a single ray can make it through the pinhole, and an inverted image of the sun will be formed on a screen behind the pinhole. By tracing all the sun's rays that make it through the pinhole you can see that the pinhole acts just as if it were a (primitive!) lens. 
A: Let us start from the basics. Consider a point source of light placed on the principal axis of the pin hole camera as shown in the diagram below:

The point source produces a circular illumination on the screen. Now let's displace the point source towards $D$ from the centre as shown below:

The circular illumination also moves away from the centre but in the opposite direction i.e., towards $d$. For the time being let us assume the displacement of the object is small compared to its distance from the pinhole. So that we can still consider the illumination on the screen to be nearly circular for the sake of simplicity. I've shown the displacement along one direction. But similar phenomenon happens for displacements in all other directions perpendicular to the principal axis. I'll leave it to your imagination to play with the system.
Now, let's consider an extended object which consists of four point sources of light as shown below:

The circular illumination due to the central yellow point source is also at the centre. But for off-centred red, green and blue point sources, the illumination is also off-centred as per our previous result. The corresponding inverted image formed is also shown above.
It's not necessary for the extended object to be made of point sources emitting different colours (wavelengths to be more precise). I've just coloured them differently to make the point clear.
Sun is not a point source and is an extended body which contains infinitely many point sources. Similar arguments can be used to explain why we observe the image of eclipse instead of a circular patch of light.
To witness the solar eclipse of December 26, 2019, I too made a pin hole camera and the image of the eclipse is shown below:

Don't get puzzled by the three images of the eclipse numbered one, two and three. I just made three circular holes each of different diameters ($r_1<r_2<r_3$) to check which one gives the best result.
As explained by Farcher in his answer, there exists an optimum pinhole diameter for a given wavelength of light and distance of the pinhole from the screen. If the pinhole is too small, then the diffraction effects would become significant. Also the intensity of the image decreases with the decrease in the pinhole size. When we increase the pinhole size, the intensity increases, but at the same time the image becomes more blurred as the circle of illumination grows in size. With the given order of pinhole sizes you could also verify this from the image above (although the difference between the second and third image is not that pronounced in this image).
As per the Wikipedia article on pinhole camera the optimum diameter $d$ of the pinhole is given by the following expression: 
$$d=2\sqrt{f\lambda}$$
where $d$ is pinhole diameter, $f$ is focal length (distance from pinhole to image plane) and $\lambda$ is the wavelength of light.

Image courtesy: My own work :)
A: The important thing is that it is a small hole
in the cardboard.

(image from Wikipedia (German) - camera obscura)
Therefore every point of the original (the sun)
produces a small spot on the screen.
So you get a fuzzy image of the sun on the screen.
A: The images which I remember are the following   
 
which show that there is an optimum size for the pinhole but never is the image as sharp as you might expect from that which is formed using a lens..  
If the hole is too small diffraction becomes significant so that the final image becomes blurred.  
If the hole is too big the final image also becomes unacceptably blurred.
To explain this consider the following diagram with there being three very small pinholes $X,\,Y$ and $Z$ and ignore diffraction effects.
 
Only a narrow cone of rays (red) which start off from point $A$ on the object can pass through pinhole $X$ and arrive at the screen to form image $a''$ with the image, $b''$,  of the bottom of the object, $B$,  being formed by the rays which also pass through pinhole $X$.
Images $ab$ and $a'b'$ are formed by small pinholes $Y$ and $Z$ but in different places on the screen.  
If the hole is of size $XZ$ you can consider it as a series of very small pinholes from $X$ to $Z$ and producing a series of overlapping images between images $a''b''$ and $a'b'$ 
As the hole $XZ$ gets smaller and smaller there are still overlapping images but the overlap is less and less until an image is formed which is a fair reproduction of the object because the overlap is relatively small compared with the size of an image formed by a very small pinhole ignoring the effects of diffraction.
A: To directly address your comment:

If we place a single point source of light in front of the pinhole then it creates a circular illumination on the screen, but if we put an extended object in front of the pinhole then it creates an inverted image of the object on the screen, how? An extended object can also be considered as a collection of infinite point sources of light. If one source produces a circular patch then infinite sources should also produce the same circular patch, just of greater intensity. The shape of the patch should not change. Why the shape changes to the shape of the object on the screen?

That's almost correct, but not quite.
You're right that a point source will create a (very small) circular image on the screen. You're also right that a large object is essentially an infinite collection of point sources.
Your mistake is in thinking that an infinite collection of point sources ought to produce a single circular image. Actually, an infinite collection of point sources will produce an infinite collection of circular images on the screen. Moreover, the circular images will all be in different locations on the screen. Together, these infinitely many tiny circular images, all in different locations, form an image of the object.
