Can you activate an iphone to any carrier?

Say I bought a used iPhone for Verizon, at&t, t-mobile, etc. And I have sprint, can I activate the iPhone to sprint even though it was made for another carrier? If so, how?

If you unlock it and some may have different sim cards

If you want to use the phone on Sprint, you should buy a Sprint / Verizon / Cricket / Virgin iPhone so you can get the phone flashed to Sprint. If you get Sprint phone then no need to flash, you can just get it activated on Sprint. Check online for flashing iPhone to Sprint.

Need to unlock it first