On coaxial helicopters, how exactly does the yaw mechanism work?
Mechanically it's simple, and ingenious.
The following is from a 1966 patent titled: Coaxial rigid rotor helicopter and method of flying same (US3409249A) by United Technologies Corp. (Of course this is not the only way, but it's one way as invented by a major aerospace company over 50 years ago.)
I've done the laborious reading referencing numbers and text, and I'll summarize it here.
Swash control

(Don't mind the steering wheel, it's the inventor's idea of pushing the cyclic left/right.) I've added an arrow pointing to 274 in the illustration, it's a wheel, and it's the key.
Using the collective (254) translates that wheel forward and aft, which moves the rigging of both swash plates up/down collectively.
But using the anti-torque (yaw) pedals, rotates that same wheel by way of cable 328. The wheel rotation would move the rigging for each rotor opposite each other.
Below is a simplified elevation view for the effects of translation and rotation of the wheel on both swash plates:

Swash mounting
For yawing, the summary is that the up/down translating parts do not rotate. It is the attachments from plates to rotors that do rotate and are on bearings. Basically two of the same but in a concentric manner.

The two main element per rotor are bearings that permit the vertical translation of the fixed portion, and the rotation of the attachments to the rotor. Focus on labels 136 and 140 (added arrows for easier finding) for the upper rotor, and here's the quotation:

(...) Bearing 136 is positioned between ring member 132 and fixed housing 52 so as to prevent rotation of ring member 132 about the axis of rotation 28 but to permit translation of ring member 132 along axis 28. Swash plate mechanism 130 also includes inner gimbal ring 133 which is pivotable about axis 134, outer gimbal ring 135 which is pivotable about axis 137, and ring member 138, which is supported from ring member 135 by bearing 140 for rotation with blades 96 about axis 28.

(Emphasis mine.)