Unlocking your phone is 100% legal worldwide. However, depending on your country, you may be required to get permission from your carrier to unlock your device.
Some countries devices may already be unlocked, please check with your local carriers regarding your device for more information.