Rooting a phone will not carrier-unlock it, but it will let you customize the operating system or install a new one. Both types of unlock are legal, although a SIM unlock often requires help from the network/carrier.