Most networks did lock their phones, unless you bought the contract from someone like CPW or P4U.
But the law states that if the handset is unlocked then the unlock code must be given out on request (even if there is a charge associated with it).
In the case of o2 and AT&T with their iPhone, they won't unlock a phone until the contract has run for at least 12 months.
If you bought an iPhone in italy, hongkong or australia however, they come free of simlocks, as their monopoly laws prevent the forcing of a contract through one supplier - although a manufacturer has got the right to secure an exclusivity deal with a certain network.
My samsung omnia was from vodafone direct, and is fully unlocked. If I flash the rom with the latest software version it removes all the branding as well, pointless though as the phone has vodafone written on it anyway!