Another way to look at things is that carriers subsidize the cost of your phone in exchange for you signing up to a fixed-length phone contract with a set monthly price.
Whether or not you can unlock your phone really has nothing to do with this, as you're committed to the contract either way.
The real issue is what happens after you've completed the 18 or 24 month contract. The carrier recouped their subsidy on the phone and has profited from your contract. But you can't use your phone (which you have more than paid for) on any other network.