Yes, iPhones can be unlocked, but what that means and how to do it depends on which kind of "lock" you're dealing with. There are three common types:
1. Passcode/Face ID/Touch ID lock (screen lock) This just restricts access to the phone's contents. You unlock it by entering the passcode, or using Face ID/Touch ID. If you've forgotten the passcode, you can erase the device via Apple's "Erase iPhone" option (after enough failed attempts) or by connecting it to a computer with Finder/iTunes and restoring it in recovery mode — but this wipes all data unless you have a backup. If the phone is protected by "Find My iPhone" (Activation Lock), you'll also need the original Apple ID and password to set it up again after a wipe, so this method won't help with a stolen or secondhand phone unless you know those credentials.
2. Carrier lock This restricts the phone to working only with one carrier's SIM cards (common on phones bought with a contract or installment plan). To remove it, you typically contact the original carrier and request an unlock, which usually requires the account to be paid off, not reported lost/stolen, and to have met any minimum active-service period. Once approved, the carrier processes it remotely (sometimes instantly, sometimes within days), and the phone can then accept SIMs from other carriers.
3. iCloud Activation Lock Tied to "Find My," this prevents anyone but the original owner (or someone with their Apple ID credentials) from activating and using the device. Legitimate removal requires the original owner to sign out of iCloud/Find My, or provide proof of purchase to Apple support if they no longer have the credentials. Be cautious of third-party services or tools online claiming to "bypass" iCloud lock for a fee — many are scams, and using them on a phone you don't rightfully own may be illegal.
In short: yes, unlocking is possible, but the legitimate method depends on which lock you're facing and generally requires proof of ownership or account access.