After the introduction of the cell phone to the masses, the handsets were supplied by the service providers i.e. the phone companies. This was mainly to ensure that the user or the subscriber does not switchover to other competitors in the industry. The handset was programmed to be used exclusively by the same service provider. The handset would not accept the SIM or RUIM card of any other service provider. But in due course of time some engineers and technicians learnt the art of opening the lock of such phones so that they may be freely used by the user with any service provider.
The reason behind binding of handsets to a particular SIM is done to prevent users from shifting to some other service provider. In many countries like the U.S, Canada and European countries, cell phones are sold on contract basis, where the customers have the facility to pay the entire cost of the handset in installments. This is most common in high end smartphones like iPhones, Samsung Galaxys, Sony Xperias and other similar phones.Hence they are locked to prevent use of the handset until the entire amount is paid. Also it is illegal to unlock them until the contract terms are fulfilled which varies from one service provider to another. It is obligatory to complete all the installment payments before you facilitate unlocking of the device.
This unlocking is very much useful if you wish to change the service provider but want to retain the same handset. It is also necessary in the event if you wish to sell or exchange your used smartphone with a new one.
In many countries, unlocking is illegal or legal only with a particular set of terms and conditions. Hence, before going about it, you have to check the laws of your country.
Unlocking is done with the help of some special softwares or programs. Many of these special programs charge on a per handset basis depending on the handset and service provider. Unlocking is also done in many handsets with the help of secret codes which vary with every handset.
NOTE: Remember that by unlocking a handset you will be able to use it with the same type of card mainly a GSM service provider with any other GSM service provider, and a CDMA service provider with any other CDMA service provider. In no way you can use a GSM card with a CDMA handset and vice versa. However, now-a-days some handsets have started supporting both GSM and CDMA SIM cards in the same SIM card slot.
Also bear in mind that a GSM handset uses a SIM card whereas a CDMA handset requires a RUIM card.