Unlocking your phone means that you can use it on many different networks around the world. Naturally, service providers don't want that to happen, so they may have put a SIM lock on your phone, restricting access to just its own network. If your phone isn't already unlocked, it's actually quite easy to get it unlocked. The legality of the practice is what's in question here, but there is good news! For most countries in the world, it's actually against the law to lock a phone to a certain network.
Now, the United States, Canada, and the United Kingdom do not have any laws prohibiting SIM locking, so service providers in these countries such as AT&T, T-Mobile and Rogers may indeed lock GSM phones; however, these phones can be unlocked by request, but that request will cost some money. Other countries, such as Hong Kong, allow cell phone companies to lock phones to protect subsidies (such as discounted phones in return for a term contract). Once the contract ends, the service provider must provide the customer with the unlock code to unlock the phone. Locked phones are used as a way for service providers to recoup the discounts they offer on their phones before customers take them to another carrier.
If you have an iPhone, you may have heard of the practice of "jailbreaking." Jailbreaking an iPhone allows the user to run applications not available from the authorized Apple store. This allows a greater number of apps to be available to an iPhone user. It is often done in conjunction with unlocking the phone to be used on other carriers. This is in fact legal, although Apple has tried to discourage the practice.
Those who own locked phones will find that the instructions and steps for unlockingmobile phones are rather easy; in fact, if you can get your carrier to give you the unlock code, you can do it yourself with relatively little hassle. However, service providers aren't very forthcoming with this information, and may withhold it from you if you're still under contract with them. To circumvent this, there are companies who will gladly unlock your phone for a small fee—whether or not you're under contract. This will allow you to use your GSM phone freely around the world on any GSM carrier you'd like, as long as you have a SIM card for that carrier to put in your phone.