It's not necessarily a scam or a fraud for a recruiter to ask for code samples. They want something to evaluate you by. It could be something they ask in total innocence. But it's nevertheless illegal for you to give them code you wrote for another employer. If they don't see that, I'd say, "Suppose I was applying for a job as an auto worker. Would you ask me to give you a car that I had built for General Motors so you could evaluate the quality of my work? Don't you think GM would object to that?"
Writing some sample code just to give them something to look at seems like a reasonable solution to me. They asked for more? How much did you give them, and exactly what did they ask for? If you gave them one 10-line function and they said, "Well, that's nice, but we really need to see more than that", I think that's quite reasonable. If you gave them 20 pages and they want more, I'd ask what specifically they want to see. If they say, "We need to see an example of a class with subclasses" or "... of a complex SQL query" or some such, okay fine.
If they say they want to see code that meets some requirements specified by them, I'd start to get suspicious this was a scam. Like last time I was looking for a job, 5 years or so ago, I saw an ad from one company saying that they wanted applicants to develop a complete system with such-and-such screens and reports, thoroughly debugged and complete documentation, for them to evaluate. My thoughts were, (a) This sounds like a scam. They want a system meeting these requirements, and rather than paying for it, they want to get people to write it for them for free under the guise of a "job application". And (b) Even if an honest attempt to evaluate job applicants, developing a system of the size and complexity they described, yes, it was a small system, but still half a dozen screens and a dozen reports, would surely be a week or more of work, and writing quality documentation would be at least days more. There was no way I was going to devote 2 weeks of effort to applying for one job, not even for an interview, but just to sending in an application. How many other jobs could I find and apply to in 2 weeks of effort?
If someone demands that you break the law and/or violate routine ethical standards as part of applying for a job with them, I'd naturally wonder what they'd expect of me AFTER I had the job. Seriously, if I have to violate copyright law and confidentiality agreements to get the job, once I'm there will they be asking me to defraud stockholders, cheat customers, and file false income tax returns? If they just didn't think it through, I'd explain the problem. If they say, "Oh, good point, we didn't think of that. How about we do X instead?", I'd say okay, maybe they really just didn't see the problem. But if they knuckle down and say, "Do this or you don't get the job," I'd say "Nice talking to you, good-bye."