According to About.com, it is legal to unlock an iPhone, as of Aug. 1, 2014. The Unlocking Consumer Choice and Wireless Competition Act makes it legal for anyone who has fulfilled the requirements of their phone contract to unlock their phone and change carriers.
Although the law is intended to increase consumer choice, there are still other technical barriers outside of the law that may make unlocking difficult. According to CNet, unlocking does not always mean that a phone will work on another service network, due to the difference in carrier platforms and spectrum holdings. However, the law is beneficial to users who travel abroad for avoiding roaming fees.