I cannot tell you why your keyboard does that but I can tell you about similar (not identical, just similar) experiences that I and others have had.
I have two systems on which the keyboard works right almost all the time. At random intervals (sometimes once a week, sometimes several times an hour), several keys that I type will be lost. At other times, strange keys will be inserted.
In all cases, when such a glitch happens, the keyboard LEDs (numlock, etc.) will flash.
I had thought it might be a bad wire causing a power fluctuation and therefore keyboard MCU reboot. But there are many other possibilities. I found, for example, on AskUbuntu this somewhat similar question about keyboard and mouse problems. In one of the answers there, John Siu speculates:
There are multiple possibilities and I cannot be sure. I will list the
most probable causes to my knowledge: (1) Pure software: Linux driver
is not handling the 1.1 port correctly for this chipset. This will be
the most possible cause. (2) Partial hardware: USB port are sensitive
to static and can degrade/die over time, especially for older
motherboard and chipset. Your 1.1 port maybe degrading and is not
functioning very well, and the Linux driver is not able to deal with
those special case (like voltage fluctuation), . . . .
In another answer there, fossfreedom speculates that if it is not a voltage/current problem or a failing USB port/hub, then it is probably a kernel problem.
While it might, in my case, be due to the kernel, my problem has persisted through several kernel upgrades. The two computers that it happens on both have different brand keyboards and the boxes are different. The similarities between the two are that both are running Debian on Dell hardware.
In this thread in a linux/debian/user group, one person had similar problems to mine, but on very different hardware, and observed the problems with Debian but not with ArchLinux. Others there thought the problems were instead due to an inadequate power supply that might be overstressed when other system components suddenly demand too much power.
Another user reported random keyboard failure under Ubuntu and ArchLinux. After some speculation that the problem was due to X.org's keyboard settings, that user's problem was solved when he bought a new keyboard.
In sum, others have observed somewhat similar glitches and, unfortunately, the specific cause is very hard to diagnose: it could be in the power supply, in a cable, in a USB IC, in a USB driver, in a keyboard driver, or somewhere else in our very complex modern computing systems.