As of February 11th, 2015, phone carriers in the USA are required to unlock phones if requested by the customer.
Why were phones locked in the first place? Well, since phone providers offer subsidized phone prices that are cheaper than unlocked phones, it became common practice (and legal) for them to lock phones, and it was somehow illegal for customers to unlock them.
Now, though, revisions have been made to the laws causing this complication. Now, the following is in effect:
Postpaid Unlocking Policy. Carriers, upon request, will unlock mobile wireless devices or provide the necessary information to unlock their devices for their customers and former customers in good standing and individual owners of eligible devices after the fulfillment of the applicable postpaid service contract, device financing plan, or payment of applicable early termination fee. Prepaid Unlocking Policy. Carriers, upon request, will unlock prepaid mobile wireless devices no later than one year after initial activation, consistent with reasonable time, payment or usage requirements.
These rules have actually been in place for quite some time, but carries had until today, February 11th, to follow all of the rules (before, they had to follow at least half of them by May 11, 2014).