If a human copies someone else's code verbatim, they should attribute the source, yes. If they learn from it and write original code, no, they don't have to cite every single piece of code they've ever read
Yes, you've stated the current social and legal rule we have to follow.
But I don't think you've given any moral justification for the rule, and in particular, why LLMs (who are not humans and have no legal rights or obligations) have to follow it.