This article will hopefully answer these questions.
Figure 1 shows a simple-minded idea of a camera (the old fashioned, non-digital kind). You have a box. In the back of the box is photo-sensitive paper. In the front of the box, you have a hole to let light in. Light from an object (a pencil in the picture) goes through the hole and falls on the photo-sensitive paper, making a permanent image.
So the first question is: Why do you need a lens over the hole? The simple answer is: to make sure that the image is in focus. But that just raises the question: what does it mean to be in focus or not?
In the second figure, I’ve done some ray tracing to show how light from the object travels to get to the image. I’ve concentrated on light from the point of the pencil. As you can see, light from the tip goes in all directions. A ray of light from the point entering the camera at the top of the hole will arrive at the paper at a slightly different location than light entering through the bottom of the hole. So instead of the image of the pencil point appearing at a specific spot on the paper, it’s smeared over a wide area. That’s what it means to be “out of focus”: the light from a single point on the object does not show up at a single point on the paper.
That is where the lens comes in. Because the lens is made of something with a higher index of refraction, light passing through the lens is bent. To get the image in focus at the back of the camera, the lens must bend light from the top of the hole downward, and must bend light from the bottom of the hole upward, so that they meet at a single point on the paper. This is only possible for a particular combination of lens + distance to the object + distance from the lens to the back of the camera (as given by the thin lens equation: 1/f = 1/o + 1/i, where f is the focal length of the lens, i is the distance of the image from the lens–which is the distance from the front of the camera to the back, and o is the distance of the object from the front of the camera).
Going back to our simple-minded idea of a camera as a box with a hole in it, we can see why, if the hole is very tiny, a crisp, in-focus image is possible without a lens. If the hole is very tiny, then there is only one place on the paper where light from the pencil point can fall. There is only one point where the light from the eraser will fall. So the image of the pencil is not smeared out over a region–it appears at a precise location on the paper. So the image is in focus, regardless of the distance from the object to the camera.
It seems like a superior way to do cameras, because there is no need for focusing. The drawback to a pinhole is that only a tiny amount of light gets through to form the image. So the advantage to using lenses is really that it increases the amount of light that gets through.