Tones are used, primarily, to reduce interference from intentional or unintentional transmitters.
An intentional transmitter would be another radio station (a mobile or base user or another repeater) operating on or near the same input and/or output frequencies. An unintentional transmitter would be some electrical device that is putting off noise on or near the frequencies in use.
These codes (PL for private line also refers to various flavors of CTCSS:
CTCSS (PL) Tones , DCS, DPL, etc, etc).
The idea is that if a transmission does not have the right "code" (which is either a sub-audible tone or a digital code) then it can not break the squelch of the receiving units, effectively preventing a repeater or another station to "key up" and listen/transmit depending on what the station is used for.
A transmission with the right code will key up the listening station(s). The listening station is basically "looking" for any transmission with the right code.
Some operators program their repeaters and other stations with codes so they can hold private or closed coversations. Unless you use a scanner that can give you the code in use (and some transceivers have the ability to listen for the tone/code being used) then an unpublished code will prevent you from "getting into" a repeater unless you run through the possibilities and get it right. In the case of a closed system, if someone really wants privacy, they'll use encryption. Encryption is illegal for use in most if not all of the non-commercial/public safety services (such as GMRS and ham radio). On those non-commercial/PS services, all means of communications must be open and available to the public (such as DSTARS, P25, etc).
Modern scanners essentially listen to the entire transmission giving you the codes (if any being used) as well as the traffic being transmitted (data, voice, etc) and they are programmed to discern any codes in use.
I think I've got that right, please correct me if I am wrong and I hope that answers the question.