The function of this kind of joint is to connect two bones, but to do so in such a way that the bones (or at least the bone that is the "ball") will be able to move in any direction whatsoever.

To me, the best example of this sort of a joint is the human shoulder joint. Think about how your arm can move. You can move it in any direction and at any angle. This is because it is the "ball" in this ball and socket joint.

By contrast, your knee cannot do this since it is a different kind of joint.

The e notes link given below defines a ball and socket joint as follows:

Ball and socket joints are multiaxial, synovial joints. They are lubricated by a clear, sticky fluid called synovia.

Multiaxial means "Having more than one axis. The ball and socket joint has at least three axes on which it rotates."

Axis means, "A central or principal structure about which something turns or is arranged. The cup-like structure of the ball and socket joint is the axis where the distal bone rotates."

And, the synovial fluid is A transparent, viscous fluid found in the synovial joints. It lubricates the ball and socket joint for easier movement."

It describes a ball and socket joint as follows:

Also called spheroidal joints, the ball and socket joints are formed by the rounded or "ball-shaped" head of one bone fitting into the cup-like cavity of another bone. The articulating bone fits into the cavity and allows the distal bone to move around. The hip and shoulder joints are examples of the ball and socket joint.

The e notes web link describes the functions of the ball and socket joint as follows:

The ball and socket joint provides swinging and rotating movements. The articulating bone is received into the cavity of another bone, allowing the distal bone to move around three main axes with a common center. The joint has stabilizing ligaments that limit the directions and extent to which the bones can be moved. However, the ball and socket joint is the most mobile in the body.