It depends on the phone.
All iPhones are locked. You have to request an unlock code through customer support.
All the lastest Galaxy S8 are locked.
All the others handsets are unlocked.
You have to look for the handset spec and see if it support the others carriers frequencies.
If you buy an iPhone 6S or 7, if you unlock it, it will be compatible with all the others carriers.