They rely on the fact that you granted them this right by agreeing to their ToS which allows that use. I doubt any court would consider this illegal.
Because I'm pretty sure it doesn't. Section D4:
> This license does not grant GitHub the right to sell Your Content. It also does not grant GitHub the right to otherwise distribute or use Your Content outside of our provision of the Service...
> there will not be derivative works of closed source at least from a copilot use case point of view.
which is inaccurate, since many public repositories on Github aren't open source and ended up in Copilot's training corpus anyway.