Before autofocus became a standard photographic feature, there wasn't a great need for lenses and cameras to communicate with each other. Today the situation couldn't be more different, as cameras and lenses are ever more reliant on electronic communication.
The introduction of autofocus necessitated a way for the camera to instruct the lens to drive, so that focus could be achieved. Subsequent improvements in lens technology also relied upon these contacts, such as for communicating distance information from the lens and subject to the camera (used to determine metering and flash exposure, for example), as well as for lens-based image stabilisation systems.
It is also through these contacts that a camera can tell whether the lens has malfunctioned, and warn you by the appropriate error code. For these reasons, it's important to take care of the contacts on both the body and lens, so they don't accumulate dirt or get damaged. If dirty, it's possible to clean these contacts using isopropyl alcohol and a soft brush, though care should be taken.
One of the advantages of this communication is that it allows a camera to store metadata. The name of a particular lens and (with zoom lenses) its current focal length will be typically stored, as well as settings such as aperture. Knowledge of the focal length of a lens can also be used to correct certain aberrations such as barrel distortion. Likewise, if a lens is set to a particularly wide aperture, some newer cameras may act to remove vignetting from the peripheries of an image.
Adding more contacts allows a camera manufacturer to keep the same mount while upgrading the lenses to a different specification, although the cameras on which they are used must also face similar changes for a connection to take place. When Olympus and Panasonic launched the Micro Four Thirds system, for example, they added two electrical contacts to the existing nine found on standard Four Thirds lenses. This was done for a number of reasons, notably to support movie functionality and any other future developments.