At the Q&A session for the Uncarrier event today, T-Mobile confirmed that devices are locked to the carrier at purchase. However, if you cancel your service, you have a few options if you bought your phone from T-Mobile on a payment plan.
The first is to pay it off all at once and wash your hands of T-Mobile entirely. This is the only thing you have to pay to leave T-Mobile early. However, you don’t even have to do that! Your second option is to continue paying for the phone monthly and not subscribe to T-Mobile service. Finally, you could return your device to T-Mobile and have it assessed for a “fair market value” credit to go toward the remaining balance on your phone payments.
Once the phone is paid off, T-Mobile can immediately process a SIM subsidy unlock for the device. This is especially important for iPhones, as they do not use unlock codes. Instead, iPhones use Apple-controlled whitelisting signals sent to iPhones when synchronized with iTunes on a computer. T-Mobile agents in stores will be empowered to immediately process a request to get the device whitelisted by Apple right after it is paid for.