Any mobile phone, iPhone included, can be “locked” to a specific carrier, so only SIM cards from that carrier can be used in that phone. This is to require you to stay with that carrier if the carrier subsidized the purchase of that phone. The carrier can subsidize the purchase either by selling you the phone directly, or by paying a retailer to sell the phone tied to that carrier.
The carrier such a phone is locked to can only be unlocked by that carrier. Most major carriers will unlock the phone once certain conditions are met, such as paying off the cost of the phone over time. However, some “reseller” (MVNO) carriers that don’t have their own networks, but instead buy network capacity in bulk and then sell it to you will not unlock your phone, or will make it difficult to unlock it. Examples of reseller networks in the US are Tracfone, StraightTalk, Boost, Cricket, Optimum. (I’m not saying any of these will not unlock a phone; you have to ask each one.)
You can buy phones in the US that are not locked to any carrier, but you must buy them directly from Apple.
There are sellers in the US who say they sell unlocked phones, but really don’t; what they sell are phones that can be used on any US carrier, but will lock to the first carrier they are used with.
If you have a locked phone the only way to unlock it is to ask the carrier who holds the lock to unlock it. Here is more information→How to unlock your iPhone for use with a different carrier - Apple Support