I thought whichever one is plugged in second is the one that receives the charge, but it may be vice versa. Either way, it's the order of plugging that matters.
Does a device even know that it's connected to a ded cable? I'd imagine that it's only after you plug in the second device that they both suddenly see they're being connected to something.
I believe that some cables (especially conversion cables) can have some sort of processor. I have no idea if that's the case with USB-C cables, though.
If there are two ground pins in the connector and the cable shorts those two ground pins, the connector could use the presence of continuity between those two ground pins to know a cable is plugged in but not connected to another device. Something like that.