The word "demon" comes from the Greek, daimon, which was seen by that culture as a personal familiar or in the fashion of a guardian angel, a little spirit that was associated with various objects and features about the house, such as doorways, plants, family pets, fountains and so on. Each daimon ensured the health and function of that part of the house, and was acknowledge lightly by the inhabitants, the Greeks having a casual attitude about their polytheism.
The Romans called these daimon by a different word, genius, which can be reckoned in the Roman culture as the "soul" of a thing, metaphorically. The door and doorway that blocked the burglar from entering did so because it appreciated the inhabitants, and they in turn appreciated the genius within the doorway, as well as the genius that resided in horses that drove well or the cart that did not break, or the one in you, you lucky thing, that made you so smart.
The daimon, or genius, in a thing could undergo an apotheosis, becoming a god, just as the genius within doorways was eventually, after centuries, interpreted as Janus, who was related to many things doorway-related. The importance of Janus in Roman culture is really interesting, but I don't want to be side-lined here so I will leave off from that.
The medieval concept of daimon, daemon or demon arose out of the Christians' blanket condemnation of all things pagan, a process that began in the 4th century as the adopted Christian religion began to clean house in ancient Rome. It must be remembered that Christianity was born of Rome (and not Judaea), that virtually all the believers who suffered through the various persecutions were all Roman in citizenry, whether they happened to be Spanish, Italian, Greek or Anatolian in ethnic heritage. When the Christians finally got in control of the Empire, they meted out to the pagans as persecution was meted out to them, resulting in a pogrom against all things non-Christian from the 5th century on. Mind you, the circumstances surrounding the length and depth of this pogrom are still in contention, as many present day scholars simply refuse to believe that Christians could systematically butcher perhaps hundreds of thousands, or millions of non-believers ... despite the fact that we have several uncontested examples of Christians doing exactly that, multiple times, in the form of cities slaughtered and destroyed in the Crusades, thousands of witches burned century after century, the wholesale slaughter of Europe and 8 million people during the 30 years war, etcetera, etcetera. Oh yes, I'm quite sure the early Christians were much more restrained than their later brethren. I'm sure they gave the pagans a pat on the head, thanked them for all the business with crucifixions and lions, then sent them on their way.
The persecution of paganism that made Europe absolutely catholic by the time of the Vikings could not fully stamp out the old beliefs. We still have them, in Christmas and Easter, in kissing under mistletoe, in believing that we feel things "from the heart," in the concept of the firstborn being the most important member of the family, in the concept of luck, in giving names to ships, in the bogeyman, in words like "panacea" and "halo", in astrology and in the supposed "left hand of god," along with the symbols we still use for planets and in thousands of other casual references we make daily, without realizing these were pagan concepts. What the Christians could not destroy, things like gift-giving at Saturnalia or Gods that were just too popular, they adopted and rewrote, turning the festival of Saturn into the festival of Christ and turning the Greek God of wisdom, Sophia, into Saint Sophia, which could then have a Church dedicated to her memory by a Christian Emperor in the Christian era, Hagia Sophia, also known as the Church of the Holy Wisdom.
And pernicious beliefs that any common individual might believe in and cherish were twisted from friendly spirits into evil spirits, demons, that possessed people and turned them away from the true faith, providing an easy excuse to turn this ancient practice of thinking there's an animus in the fountain that keeps the water fresh into something that we can use to tie you to a stake and burn you to death, just to make sure you don't start thinking that maybe there's something to this old paganism after all.
Calling these things evil demons isn't enough, however. We must take the concept of the spirit possessing the well and transform it into the spirit possessing YOU; then we can expand the role of the (Persian-derived) anti-Christ devil into the master of all the demons in all the world, so that we're good and positive that there's a deliberate, contrived, world-wide plan that seeks to pollute and poison your immortal soul, run by the worst demon we can conceive of, filled up with all sorts of impressive and terrifying powers, factory-designed to scare the living shit out of anyone whose never read a book or who possesses the least understanding of how things like volcanoes and hurricanes work.
Once that scheduled PR stunt is in place, we have just the thing; give us money, we'll make sure Christ puts his loving arms around all of you. What else can possibly save you from the demons?
So, in wondering where demons come from, that's where they come from. This doesn't tell us how they function in a D&D campaign, but it does give us more wiggle-room when thinking about how demons should act.
Are you sure now that they're as malevolent as the Christian religion makes them out to be? After all, that's the source you're relying on for your conception of what the word demon means. The Christian religion.
Not that I want my demons shaping up like Aahz. I admit, I intend to retain the notion that demons are malevolent. I only make the argument that they don't have to be. It's a choice, see? Not a blind compulsion.
To me, this makes the whole matter of demons ~ and presumably devils as well ~ a lot less certain. Within uncertainty, there is drama. There is adventure.