That's just not an issue in practice. All major AI labs match generated code against their training data to prevent outputting verbatim copies. They're so confident they won't output copyrighted code that they offer copyright indemnification to paid users.
They do? Last I remember microsoft's license for copilot was saying that any copyright violation is on the user and they were disclaiming all responsibility (which would probably not hold up in court).
Do they offer the same indemnification that the code they generate IS subject to copyright and that you own that?
Because the US Copyright begs to differ.