From a Christian viewpoint, it likely stems from this passage in Matthew:
" When the Son of man shall come in his glory ,...he shall set the sheep on his right hand and the goats on his left; then shall the King say unto the sheep, 'Come ye who are blessed of my Father, inherit the kingdom prepared for you from the foundations of the world.' Then shall the Kings say unto the goats on the left; 'Depart from me, you who are cursed, into everlastng fire prepared for the devil and his angels'. - (Matt. 25:31-41)
While the "sheep" and "goats" in this passage are metaphors, it seems to have stuck.
Pan was associated with nature, fertility, and wildness. He was also a close associate of Dionysus, whose intemperate and lustful behavior became associated with an array of sins. I vaguely recall a linguistic connection between Pan and the use of the term "horny" to describe sexual arousal.
The association probably originates from the Old Testament. Shepherding of herds goes all the way back to Abel, the son of the very first man and woman. I don't know when people first started to domesticate goats, but it's easy to see the contrast between sheep and goats. Sheep are docile, gentle, and easy to lead, whereas goats tend to be more independent, likes to explore, and not as easy to lead. [Please be careful not to read in modern value of independence and explorative nature into this.] The concept of scapegoat also originates from the OT, as a bearer of sin. Because of its association with sin, it was more than likely used as a symbol for defilement, where the archetype of defilement becomes devil. Although it is used positively in the New Testament as a type of shadow of Jesus Christ, it is more often used negatively, as a metaphor for the rebellious.
As mentioned already, the association to Pan may have occurred during Emperor Constantine's time when the Roman Empire instituted Christianity as the state religion (http://www.mesacc.edu/~thoqh4908...).
Sadly, there are many references in the bible (metaphors) using goats and sheep as examples of people. When it comes time to divide the good people from the bad, sheep are always playing the part of the good and goats the bad. Goats don't deserve this bad rap. They are vastly more intelligent than sheep. And as for the rectangular pupils, they do give both goats and sheep an incredible range of vision, as well as quickly narrowing in harsh sunlight.
Don't forget the cannite God Baal, which the Torah warned about. He is depicted as a minatour type figure with two horns. He is also called the lord of the flies. The world devil maybe be borrowed from the Persian world devi or destructive spirit. Once adopted it may have been used to apply to Baal. Needless to say, nobody know exactly where this depiction of devil has come from.