It's essentially a remnant from a time when the U.S. political system worked differently. (Not unlike the Electoral College itself, according to some.)
When the Constitution was written in 1787, information traveled much more slowly than it does today, and the framers believed that most people would not be well-informed about issues and candidates outside of their own state. Consequently, rather than having people vote directly for the President, they instead had people vote for electors, who would be prominent, well-informed citizens of their respective states. The idea was that people would vote for electors whom they generally agreed with and would trust to make the right decision. Electors would then use their individual judgment in voting for President.
Obviously, this isn't how the system works today, but changing the Constitution is hard, so electors are still technically able to choose who to vote for, even though their names no longer actually appear on the ballot. Some states do have laws that attempt to compel electors to vote for the candidate they're pledged to, but not all.