The carriers must get the flagship phones extremely cheap from Apple and Samsung to make these lock in deals financially rewarding to the carrier.
I don't know about "extremely cheap" but I think there are a variety of incentives at least some phone makers give carriers including marketing support, financing support, revenue sharing, etc.