An iPhone purchased from Apple can be purchased as carrier locked, or can be purchased as unlocked.
Carrier locked phones usually have a purchase subsidy.
Unlocked phones are usually at least as or are more expensive than subsidized phones.
Nobody other than the carrier can unlock a carrier-locked phone.
If you've purchased a mis-represented-as-unlocked iPhone, you're left to convince (pay) the carrier to unlock, or to discuss this purchase with eBay and/or with the seller, and/or to return the purchase if the seller is still available and amenable to that. The carrier may or may not be willing to discuss this unlock with anybody other than the person with the cellular plan involved, too. And some carriers will not unlock.
How to unlock your iPhone for use with a different carrier - Apple Support
The All Too Common SAD Reality of Buying a used iPad/iPhone - Apple Community