You must contact your carrier to unlock an iPhone. Phones are only eligible for unlocking after the contract period is over. An unlocked phone works with any carrier you choose, while a locked phone only works with the carrier that sold the phone.
If your phone is eligible, call your carrier and request to have the phone unlocked. You must meet any criteria that your carrier has for unlocking. It usually takes several business days to process an unlocking request. While you wait, your carrier can provide updates on your request.
You may have a SIM card from your carrier. If your phone has a SIM card, remove the card from the original carrier, and replace it with a SIM card from your current carrier. Usually phones on pay-as-you-go plans have SIM cards, while contract phones may or may not have a card.
Inserting a new SIM card prompts the restoration process. From here, you can reset your phone and complete the setup process with your new carrier. If you do not have a SIM card, then you should back up your iPhone using iCloud or another service. Restart your phone from the backup, and contact your new carrier to complete the process.