First off COCOTs were owned by customers, so the magic did not happen at the telephone switch. Quite the opposite.
When VoIP started emerging, a handful of COCOT companies and their operators figured out how to place long distance calls for a fraction of the usual price. Instead of placing LD calls over the telephone network, any LD call would be intercepted by the COCOT firmware. Instead, a local number would be called and rerouted over the Internet. This was a type of extender, and one could beige box these pay phones to pick up DTMF tones and figure out the number of the extender and its access codes. Sometimes an access code was even optional for a call to go through the extender. Like many extenders, these became abused like hell.