For Villains that Are Perceived as Heroes
You have to introduce this character as someone who is doing the right thing. To do this, there are a few things you should do:
Keep their motive vague until the reveal and make the villain look good. If your villain and the real heroes are both after an object, explain the properties of that object and what it’s capable of. The motives of the villain and the heroes should be a bit vague when that explanation comes along. The villain might only mention that the actual heroes don’t know how to use the object properly and that if they get it first, they’re going to ruin it. This makes your villain seem like the good guy. They want to stop others from using it wrongly or in a dangerous way. Throughout the story, give little hints at what the villain wants to use it for. Make it seem ethical.
For example, if the object is an energy source that powers people who were made into cyborgs against their will and who are used as slaves, you only have to mention that the object can power cyborgs and that the current power source is low. You might show that the cyborgs used to run factories and take dangerous jobs that regular humans couldn’t do without getting hurt and that without these factories running, the economy suffers. So it’s a good thin that your villain is trying to get this power source, right? Let some of the actual heroes say things about letting the cyborgs go free and let the villain claim they would be violent without restrictions. Later on, reveal that letting the cyborgs go free really meant shut down their failing life systems because death is a far better alternative.
Make the heroes look bad. Going on with this little world I’ve been creating, we could show that the heroes are an underground rebel group who are often arrested and caught in violence. If the villain is peaceful, it makes them look good and the heroes look bad. The heroes might try to attack the villain or they might be able to hack into the system that keeps the cyborgs hanging on to life. If they create a big electronic hassle for the villain, the reader will have sympathy for the villain and the heroes will come off as villains. This is when it would be revealed that the real heroes are trying to let the cyborgs die. One of the actual heroes can reveal that they are in pain. This will start to make the reader wonder who is right and who is wrong.
For Heroes that Turn Into Villains
This is something that you can’t foreshadow because it’s just general character development. Events both large and small change your character over time. If their motive changes or if they go through a change that causes them to seek other means of achieving their goals, they might become a villain.