What purpose do transformers have in electrical interfaces such as ethernet?
They're for galvanic isolation. This means that the grounds of all the PCs on an ethernet (say) are not connected together by the ethernet cables. If they were, it would be a violation of electrical code (in some jusidictions). Given a big enough network, there's no guarantee that the mains earth (ground) will be at the same potential everywhere. Small voltage differences may exist, and given that this is mains wiring, large currents are available.

Adding the isolation transformers means that the PCs/network devices are connected to ground solely via their mains earth wires, not via the network cables. MIDI uses optoisolators for a similar reason.