i think it woudl be the other way around. Give you the unlock code when you are in a contract because you are stuck in a contract, they get money either way...
if you are not in a contract, why would they give you the unlock code so you cancel and go to another provider with their phone???