We do not necessarily know why individual legislators decide to vote against the wishes of their constituents in any particular case. But the list of possible reasons is lengthy.
First, a legislator might have information that his or her constituents do not have, information that makes the legislator believe that this is a better decision than the constituents' choice. Legislators have staff who are supposed to keep them informed about the matters they must vote on, for example, information about a particular industry, statistics on employment, or crime rates in a particular city. Legislators are also provided information by lobbyists. Legislators often sit on committees whose job it is to have a great deal of information in one specialized area. The average constituent is quite unlikely to have as much information readily available as the legislator.
Second, legislators are under no obligation to vote the way their constituencies wish, and sometimes they decide to vote based on what their own ethical mandates require. Notice, please, that I am referencing ethics, not religion. It is important, I think, to make this distinction. When legislators do this, we say they are "voting their conscience." So, for example, a legislator whose district does not want the legislator to vote for amnesty for illegal immigrants could vote for it, finding it unethical to break up so many families this way.
Third, some legislators will vote in a way contrary to their constituencies based upon their religion. An example of this is civil rights protection for the LGBT community. Polls make clear that most people are in favor of these civil rights, yet legislator after legislator votes against them, based upon their religious beliefs. This is problematic, of course, in a democracy in which religion is not supposed to play any role in governance, but that certainly does not mean it doesn't happen. Tim Kaine, who is the Democratic vice-presidential candidate, belongs to a religion that prohibits abortion, but he is very clear that as part of government, he supports a woman's right to make this choice for herself. This is a principled position that allows him to serve properly.
Fourth, legislators are influenced by others to vote a particular way. This is the job of the lobbyist, certainly. And campaign donations and gifts can be highly persuasive. There is nothing to guarantee that a legislator will vote for what the constituents want when offered a trip to a resort or primo seats at a concert. Most legislators are allowed to accept at least some gifts, and while it might be difficult to prove causation, there is influence, conscious or subconscious.
Finally, today, there are many issues that seem to be almost evenly divided in the polls. If 49% of a district is for something, then 51% of the district is against it. This means the legislator is quite often damned for doing something and damned for not doing it. Voting as one's constituency wishes is sometimes an impossibility!
It is not reasonable to expect a legislator to vote exactly as the constituency wishes for every single vote that is taken. Information matters. Conscience matters. Religion should not matter, but it does. Then there is persuasion of one kind or another and the impossibility of representing an equally divided district. All things considered, I'm so glad I've never run for public office.