Although there are several types of "locks" that can apply to a phone, the most talked-about type is a carrier lock, also known as a SIM lock or subsidy lock.
Many phones sold by carriers come "locked" to that carrier. A "locked" phone can only be used with that carrier; it cannot be used with another carrier's service. (Not counting roaming.)
This lock can usually be removed by entering a special code or numeric password. In some situations, some carriers will supply this code upon request by the customer; not all carriers will do this.
There are also third-party companies that sell such codes, or other types of unlocking services.
Another type of "lock" is a keypad lock, which prevents accidental key presses in a pocket or purse. This type of lock is usually de-activated by pressing or holding down one or two specific keys.
A third type of lock is a security lock. This lock is like a typical "password", to prevent someone other than the owner from using the phone. If activated accidentally, the user manual or carrier customer service can usually tell you the default code.
Typical default codes include the last four digits of your phone number, the last four digits of your social security number, "1234", or "0000".