To unlock your iPhone from its carrier, you'll likely need to contact your carrier directly to cancel your contract.
If you're looking to buy a used or refurbished iPhone, you should take a few important things into consideration first.