Compressors are used to control dynamic range in musical material.
Essentially, you’re reducing the difference between the loudest and softest levels, which provides more even sounding output.
For vocals, it’s extremely common to use high levels of compression on a lead track, so that every word can be clearly heard over the music. When taken to extremes, compression can “hype” the sound, creating an effect unto itself.
When related to guitar, compression provides enhanced sustain and attack. Combined with overdrive/distortion effects, you can create very even sounding rhythm or solo sounds.
For more information on Compression see: Wikipedia Dynamic Range Compression