How do websites offer a factory unlocking service
They pay someone that works for a carrier to enter that information into the carrier database or they have hacked access to that database. 

As long as iTunes gets the device ID as one to be unlocked when it restores the device, it gets unlocked. Otherwise it gets locked to the carrier under which it was sold.