At a very generic level:
- There's a small microcontroller in the flash.
- The CPU in the camera talks to the microcontroller in the flash.
- If the camera gets the responses it's expecting, it treats it as a Canon flash and lets you do everything with it.
- If the camera doesn't get the responses it's expecting, it degrades the functionality.
Canon will claim this is to prevent third-party equipment from potentially damaging the camera. While this is maybe partially true, it also has the "convenient" side effect of meaning people need to buy Canon flashes...
As for exactly what the communication between the camera and the flash is, that's what the third party flash manufacturers would all like to know. It's proprietary to Canon and the only way other companies have discovered it is via reverse engineering.
(While the above may read like a rant against Canon, every other major manufacturer does the same. At least Sony are using a standard hotshoe these days, rather than a different physical connector they used a few years ago...)