Once your two year contract is done you can ask AT&T to unlock the phone using their online service. I've done this several times. Unlocked phones are handy; my daughters unlocked 4S was a mobile hot spot on our last Canadian road trip.
Unlocking is simple when a contract's phone number (SIM card) matches its host iPhone's IMEI. It's more complex when you've done a service swap, and even more complex when you've service swapped a defective service swap. As I'd feared, when my wife's contract was done the automated unlock form rejected her phone number.
That wasn't surprising. What was surprising is that I was able to resolve the problem using AT&T's online chat service. I described the problem and passed on the record of IMEI's I'd tracked. I actually don't think she wanted those however, the support person just wanted the current IMEI. I was told an unlock could take up to 7 days, but 12 hours later I got an unlock confirmation mail. After I 'restored' the phone I got an unlock confirmation message.
It's disappointing that AT&T still sells locked phones -- while Verizon doesn't. I hope they'll change that policy. In the meantime, I give them credit for a quick fix to my service swap problem.