Indeed; I think there's a genuine question as to whether the output of ChatGPT is a derivative work under the law or under our feelings of what's moral.
I've read a lot of code in my career, much of it GPL. When I now write code, it's based in part on that previous code reading. I think most people agree that doesn't mean that all code that I write must be licensed under GPL. In other words, they agree it's not derivative. Even if I write a C strcpy implementation that's functionally identical to one in glibc, I think most of us agree it's not derivative, even if I've read glibc's implementation before. Or if someone asks me "how can I write strcpy in terms of memcpy and strlen?" and I answer them with code I write that's very close to glibc's implementation.
Is AI-written code fundamentally different from bio-intelligence-written code in that regard? (I think the answer is uncertain in terms of "how should it work?", not that it's clearly one way or the other.)