If you purchased the phone unlocked direct from Apple and the Activation Process ends up locking it to the carrier, you can always call the carrier and demand they return it to the unlocked state since it is not a subsidized phone. After all, You paid full price for it. It's yours.
I don't think it works like that. The phone is marked to be locked at the sales point at Apple - when they make the sale of a subsidized phone, they enter in the Apple centralized database that this particular phone must be locked to a certain provider. The actual locking takes place through iTunes when you activate, restore, or upgrade the iOS of the phone (every time you perform one of those). If your purchased as unlocked phone gets locked, the fault is all with Apple, and you should ask them to fix the problem. From what I have read, they fix it by exchanging the phone. Also, these accidents happen only if a salesperson from an Apple store by mistake scans your phone as "locked" to a certain provider. Haven't heard complaints about phones from apple.ca.
Anyway, if iTunes says that "your phone is unlocked, it will be forever unlocked, and carriers can't lock it - by accident or otherwise. Neither can they unlock a locked phone - they need to contact Apple about that.
Also, thanks to recent Government intervention on subsidized phones - once your contract has come to an end (IE: your 3 years are up) you can phone your carrier and demand they unlock your phone since you have fulfilled your terms of the subsidy. I would imagine even if you cancel your contract and thus pay your early cancellation fee (which covers the balance of the subsidy), you can have the carrier unlock the phone so you can take it to another carrier.
I don't think that has happened yet.