From what I've read thus far, electronic shutter is a type of device that controls whether the image sensor is turned off or on non-mechanically.
True.
What exactly controls it and how does it turns the sensor off or on (if charge is accumulated when the sensor exposed to light by a CCD/CMOS)?
The reset line is asserted on all pixel rows in the beginning. Then the reset line starts to be slowly released to have the first curtain matching the second curtain. The first curtain could be very fast, except... it must match the slow second curtain!
The second curtain is implemented by simply reading the sensor; there is no way to turn off charge accumulation without destroying the existing charge apart from (a) reading the sensor or (b) covering the sensor mechanically. The second curtain is slow, and thus, the first curtain needs to be artificially slowed down too to have constant exposure across the frame.
If it's relatively fast, how come its flash sync is slower than a mechanical shutter?
That's a big "if". Typically, it is not fast; it is slow. Slowness is due to slow readout speed.
However, Canon with EOS R5 will apparently have "new approaches for sensor stabilization". I think the new approaches work not by mechanically moving the sensor but rather by taking electronically numerous pictures in a very short time interval. So, EOS R5 could have faster electronic shutter. Or, it could not. We do not know yet.