This sort of thing has bothered me for a long time, so I thought I'd share what I've learned so far.
First, legally speaking I haven't found any cases or legal opinions that say that the practice of a "work sample", especially when limited to 1-2 days, is even vaguely frowned upon. There appears to be some literature to support that work samples may be particularly prone to adverse impact (disproportionally favoring majority applicants, read: white males), but that's about it.
Second, ethically what makes this problematic is that there is a suffusion of a few issues. The four most pressing are:
How much can/should a person be asked to invest (in time and
money) into merely interviewing for a prospective job.
Should a person be paid for providing a non-trivial work sample?
Is it ethical to use any work by applicants for your benefit,
without those who did the work being compensated (paid) for their
Is even offering a person a job enough compensation for
performing real work?
The thing is, in all the research and inquiries I've made of HR/IO professionals, the answer is: "there is no universal code of ethics for this." It depends, and it varies.
However, this does not mean one cannot make an ethical judgement - just that it is not the same sort of ethical judgement you can make if a person were to tell you "Sorry, we don't hire Hispanics."
What it comes down to is this:
What are your ethics, and how do they compare to a potential employer's apparent ethics?
One of my ethical rules is that if a person performs real work for a business, at the specific request of that business, then that person should be payed a fair rate for their time - with absolutely no regard to future employment. A fair rate being defined as what that person was to be paid, if hired, during the initial training period.
I will share my personal reasoning as to how I arrived at these beliefs.
My first time with something like this was as a graphic artist and "digitizer", where I was asked to come in and provide real, on-site work for a few hours; the goal was stated simply - for me to see if I could really handle this sort of work by myself (it was a very specialized set of skills, with work I hadn't exactly done before), and for the business to see if I might be able to do the job and thus be worth hiring. The person said, explicitly, "I'll pay you for your time regardless, of course" - as if it would obviously be unacceptable to ask a person to work and not pay them.
This put me, as an applicant, in the position of "if they don't hire me, at least I'll make a few bucks for the trouble - which beats filling out more application forms", and "or I'll make a few bucks and get the job, which would be great", or "maybe I'll find out its a terrible job in a terrible place, and I'll just politely decline." Why wouldn't I give it my best shot, free of worry or anxiety? Let the chips fall where they may, there is no downside!
From a business prospective, this is exactly what you want - a potential chance to see how a person would really perform on the job. I got this particular job and performed exactly as I did that first day, plus getting better as I learned the job.
For my next experience, I was asked to try out as a computer/network technician. Again I was asked to give a trial of a few hours, but no pay was offered. I didn't especially like this, but I figured it was just a few hours, so no big deal. It turned into a 8-10 hour day of real, actual "this is what the business gets paid to do" work, and at the end of the day I was offered $10 to "thank me for my time" ($60 would have been minimum wage, less than half the pay the position supposedly paid).
I was offered that job, and the handling of the "work sample" was one of the reasons I flat out turned down the job and it helped to cement my personal ethic. My rule is "if a person won't treat and pay you fairly before they hire you, why on earth would you expect them to pay and treat you fairly after they hire you?" Even a high-paying position is not worth being jacked around, devalued, or having your compensation toyed with capriciously. No thank you.
YMMV, but I've found the chance to be offered to do real work for no pay to be invaluable- that is to say, the chance for me to keep looking for a different job.