You can now legally unlock your iPhone to use it with a different carrier or to be able to put in a different SIM card when you're traveling abroad. Such unlocking became explicitly illegal in January of 2013 when the Librarian of Congress, the official steward of the Digital Millennium Copyright Act, chose to uphold a provision of the DMCA that made it illegal to unlock a phone. Consumers were incensed, and over 100,000 people signed a petition asking Congress to pass a law making it legal. Both the House and Senate unanimously passed the bill, and President Obama signed it on Friday. You can read more in this White House press release.
The bill, called the Unlocking Consumer Choice and Wireless Competition Act, also directs the Librarian of Congress to determine whether other wireless devices, such as tablets, should also be unlockable. According to the press release,
This commonsense legislation ensured that consumers could transfer their phones between carriers, and that second-hand phones could be put to good use by new owners connecting to a network of their choice.... The bill not only restores the rights of consumers to unlock their phones, but ensures that they can receive help doing so if they lack the technological savvy to unlock on their own.
Of course, you still need to honor the contract you have with your carrier. But once you've satisfied that, you're free to unlock your iPhone.