As an undergrad, is it unethical to work in a field that I'm not interested in pursuing further in graduate school?
It is definitely not unethical. Many undergraduates interested in medical careers do research in, say, biology labs, since it looks good on their applications. It is common practice in the field, and no one considers it abusive.
More importantly, oftentimes people take up RA positions specifically for a purpose like yours: to figure out whether or not graduate school is right for them and, if it is, whether they want to stay in the same area or switch to a different one. Being an RA is one of the best ways to try out a particular line of research without a long-term commitment. That said, once you decide that you want to pursue research in a different area during grad school, it definitely doesn't mean that you should immediately resign (especially since you are planning to publish your work). Even though you are not planning to stay, you can still make a contribution!
The grad student that you spoke to has no idea what they're talking about. As long as you are doing the work you've agreed to do so for the supervisor, you are fine ethically. You are likely paid by a grant, and the grant was for a specific research objective -- it almost certainly wasn't to force an undergraduate to make a commitment to spend their life in a particular field. Quitting immediately would just disrupt the project, and generate extra work for the Principal Investigator.
The graduate student who you were talking to probably knows almost nothing about how/why research is funded, and is just being a jerk. I certainly didn't know much about funding when I was a grad student.
If you are thinking about shifting fields, you should probably bring it up with your faculty supervisor. They might think of ways to adjust the work you are doing to help with that transition. I think as long as you stay focused on their project while they are funding you there is little chance they'd ask you to leave.
Adding to neuranna's answer: Given that the cat is already out of the bag (you told the "secret" to someone on the team who obviously opposed the idea and might thus leak that information to the rest of the team or your supervisor), it might be wise to prepare a sound explanation of your future plans should the discussion come up with your supervisor. In fact it might even be advisable to approach your supervisor directly and put all your cards on the table. There is nothing wrong with your plan to finish up the project and publish the results. Just convince your supervisor that you can still make a worthwhile contribution. One could argue that you already know all the ropes of this project whereas a new RA might have to spend some time on training and familiarization with the topic.