Circular lens, circular image
The lens projects a circular image called the image circle. The example image below shows the full circular image formed by the lens.

The red frame in the example represents the area recorded by the film or sensor.
Why lenses are circular
Lens design is constrained by optical imaging physics, and it is difficult to produce lenses with shapes other than circular. Lenses with other shapes tend to waste large areas at the edges of the image.
Eyeglass lenses are often cut to various shapes because the imaging requirements at the edges are not strict, or because a large portion of the lens area is sacrificed for aesthetic or fitting reasons.
Historical reason for rectangular film
The rectangular shape of film is largely historical. For a long time, the dominant commercial and consumer film format was 36 x 24 mm. A standard size ensured compatibility across manufacturers.
Film was stored and used as long strips. If only the circular region produced by the lens had been used, most of the strip area would have been wasted, so a rectangular frame made more efficient use of the material.
Digital sensors and aspect ratios
With the advent of digital sensors, the exact physical size of the imaging area became less critical. However, many professional cameras retain the 3:2 aspect ratio; 4:3 and 16:9 are also commonly used and continue to increase in prevalence.
Applications that depart from rectangular sensors
Advanced imaging applications with stricter optical requirements, such as light-field photography, astronomical imaging, and panoramic imaging, are less constrained by sensor shape. As a result, non-rectangular images have become more common in these areas, and many of those images remain circular.
Practical considerations
When photography was first invented, film was expensive and could not be wasted. The circular edges of the image that did not fit into the film frame were not considered a significant loss.
Today, user experience influences many design choices, so various aspect ratios are available. Still, painting, photography, and cinema have traditionally used rectangular formats, and that convention persists for the foreseeable future.
In professional and scientific imaging, where photographing distant astronomical objects can require enormous cost and effort, every bit of imaging information is valuable and must not be wasted. Sensor shape is chosen to best serve the scientific objective, and the same principle applies to other specialized imaging technologies.