See: The All Too Common SAD Reality of Buying a Used iPad/iPhone – Apple Community
My suggestion would be that when you go shopping for your next phone, you buy it straight from Apple - either new, or from the Certified Refurbished section of the online store. My understanding is that iPhones purchased directly from Apple, in the U.S., are not locked to a particular carrier unless you buy them with carrier financing. (Check the wording that appears and disappears on the new phone ordering pages – or the descriptions of the phones in the Certified Refurbished store – to be sure.)
I'm guessing (though not certain) that Apple sells unlocked phones in other countries, too.
WIth phones from some "marketplace", they might be carrier-locked, Activation Locked, and/or blacklisted. You won't be able to get much of any use out of an Activation Locked or blacklisted "brick."