How do I unlock my T-Mobile iPhone?
Since the major U.S. carriers came into full compliance with the CTIA's Consumer Code for Wireless Service on February 11, 2015, they can no longer refuse to unlock your device (assuming you are eligible). This means you can unlock your iPhone and go to a new carrier if you wish.
To meet T-Mobile's eligibility requirements, you must have fulfilled your service agreement (or paid the early termination fee), your account must be in good standing, and your phone can not have been reported lost or stolen, or be associated with any fraudulent activity. You also can not have requested unlocks for more than two devices on that line within the past year.
If you are eligible, simply contact T-Mobile customer care and they will send you unlocking instructions. For more information, see T-Mobile's unlocking guide.