This is a fairly common question. The phone was not locked by T-Mobile. It was locked by Apple's Reseller Flex Program. In this program, resellers, like Best Buy sell a phone that is initially unlocked. After about 24 hours the phone will lock itself to the first SIM it sees. T-Mobile knows nothing about this, didn't have anything to do with it. Don't know how to unlock it. It's entirely Apple's doing. Most savy buyers know to insert a Verizon SIM for the first 24 hours because Verizon is not allowed to lock phones. This leaves the phone unlocked. If you had first inserted a SIM from Greenland the phone might have locked itself to a carrier in Greenland.
Sorry to hear that your phone is locked! I would recommend returning this phone to Best Buy and look into purchasing the device from Apple directly or from the carrier you plan to use the phone with. If you are purchasing the phone to use with multiple carriers, you will need to make sure that the seller of the phone is selling them as completely unlocked.
Apple sets their own rules as to almost any product they deal with. Example - Every other mfr. has standardized on charging cables. I assume if you buy a phone from TM directly, it would be locked to TM and they could unlock. 3rd party sellers should disclose that Apple phones they are selling might be permanently locked to your carrier.