They lock phones because carriers are willing to pay off someone’s phone so people jump ship. It’s a pure anticompetitive practice.
Further, as noted by multiple commenters (and this can be confirmed by a google search turning up numerous accounts): T-Mobile automatically locks an unlocked device when you insert an AT&T sim into it.
Which is bizarre. T-Mobile doesn’t own the device. They don’t even have a SIM in it.
This should read as “T-Mobile has entered into an agreement, which should be against public policy and illegal, such that the device vendor locks the device under certain circumstances.”
The idiotic thing about locked phones in the USA is that they're given to customers who are ON CONTRACT. Therefore, if the customer takes his phone to another network, he still has to pay the original one! Why on earth would the phone company want to prevent people from paying for service they're not even using?
The sheer stupidity of this behavior is almost worse than the offensiveness of the entire phone-locking concept.
As others have noted, that's why there is a contract in place - if you don't pay the monthly bills, they can seek to recover the costs from you.
Also, what you're saying would do nothing to stop someone selling the phone to another customer on that carrier.
Frankly, it's absurd to pay laptop prices for a phone.