Just thinking out loud here so sorry if this doesn't help.
So it sounds like you can safely assume that it's software or hardware related, as in it's a Windows problem, or one or more applications running on Windows.
I was going to wonder if the USB port(s) was bad, until I read that it only happens when you're playing online.
And you're 100% certain about that?
If so, to me the only logical conclusion would be something network related causing your FPS to drop which could be perceived as a mouse issue. Can you try using net_graph 3 to monitor your network status while you play tf2? If choke/loss increase at the same time the mouse issue happens, that could be it.