Cheating might or might not be illegal, at the very least it's morally wrong (is that even worth discussing?). And fully doing someone's homework, for free or paid, is helping them cheat (in terms of laws there is an equivalent for that), which is just as wrong.
But the latter surely isn't illegal in terms of homework (it might be in the context of an exam). It's just morally wrong.
I typically tell the person asking that it won't help them on the long run. If they decide to ignore that: let them pay and learn that lesson on their own later on. And if someone accepts that money after an appropriate warning... It's imho still wrong, but again, they have been warned. Paying money for what you think will help you is a lesson on its own.
However: yes, you can learn from studying code others wrote. But only a small fraction of what you can learn doing it yourself. Reading code and writing code are completely different things. Plus, from experience, copied homework usually isn't looked at, no matter what they say.