If it walks and talks like a bike, and only goes as fast as the average cyclist, it is probably a bike. But if it has a throttle and goes faster than your average cyclist, it's probably closer to a moped at which point you need a license, different kind of helmet, turn signals, registration, so on and so forth.
Older bikes used the circumference of the wheel and a count of rotations to calculate the speed, so people could de-limit them by changing the stored circumference constant in the eeprom. Modern e-bikes use a combination of sensors at various locations to detect motion, acceleration, pedal force and tilt angles to decide how to apply the power but I think even with those added sensors, the speed is still detected via the wheel rotation sensor.
Seems some people don't like the regulations as the parent comment got downvoted, rest assured I did not single handedly write the global regulations, and I don't like the speed limiter either.
The high-end E-Bike I rode briefly did a marvellous job of detecting road conditions and maintaining semi-constant speed. The ones I use on the street are more crude, they use pedal effort as a primary guide to intent but back off aggressively, I guess to limit risk to pedestrians. I am pretty sure off-road wouldn't want that. (not a big e-Bike rider, just fascinated)