The short answer is software. Phones tied to a specific carrier are locked by carrier software. An unlocked phone doesn’t have that software. 

But don’t fret, the Unlocking consumer choice and wireless Compilation Act lets you unlock your carrier phone once you’ve paid for it fully and finished any contracts or agreements.