It's among questions often asked. Why are things so messed up? How did 'everything that was created good,' -go so bad? Did God create evil?
Those are bad questions.
'Things' are better than they were in the past and have been trending up for thousands of years now. Everything was not created 'perfect' but rather things were created unformed, and God has been forming it ever since and continues to do so... hence the way that things are slowly improving.
--Where did "demons" come from, if not created?
"Demons" arise through the act of demonizing. People do that, not gods or titans or giants.
And is earth in some sense-- a prison? Or is it a school? What is it? What is the purpose?
Earth is humanity's home, past and future. At the end of this story, the people do not become light-beams and fly away to space. Rather, God comes down to the earth to be with His people.
Salvation is found in God's Incarnation; not man's disincarnation. This is the pattern of the thing - Emmanuel - God with us.
-The confusion, might be your own. I've come to use, interchangably the terms- angels and spirits. Both terms can be used loosely to describe these divine beings that scripture calls elohim. In a more technical understanding-- angel (malak) is properly understood as a function of an elohim. It is used to describe what the elohim/divine/spiritual being is doing-- acting as an emissary, or messenger and delivering a message. How these angels do that is in spirit, as they are spiritual beings and not corporeal. You might see and interact with them while you are in spirit-- that is, while you are dreaming. Or, you might interact with them while they appear 'in-person' -- that is, while a person is wide awake, an angel visits them, rests upon them, guides them, and prompts them to say or do certain things in a way that you might think of as akin to a rider on a horse. He reins, or spurs, or prompts in ways the horse understands and has learned to follow, and one does the will of the other to whatever extent the horse is willing.
They aren't interchangeable that way. You are correct to say that
malaak/angel is a function or title, but that function isn't exclusive to spirits. Seraphim and Cherubim/θρόνοi are angels with physical form, but not the physical form of men. And men and beasts and even the stars of the sky can function as God's messengers.
While we're at it, the Hebrew word for king (malak) is functionally identical to its word for angel (malaak) because they share a meaning. One acts as God's representative to mankind, and the other does too. All kings are angels, and it isn't because they lack a body.
It's the same with these fallen ones, you call devils. They weren't always devils, but were created good. They "fell" into idolatry and sin and were separated from the holy ones who remained in the presence of God (in the heavenly realm) and these fallen ones were sent away and confined to the earthly plane. This isn't a spiritual place. It's physical. Spirits don't roam free-- they must be contained and as such they only have influence -in you- and in me, and even in four-footed beasts as Enoch tells us. The concept is emphasized in the scriptures where the demons plead to be sent into the herd of pigs rather than a place of torment. This is where the idea of demon-possession comes from and it's the other end of the spectrum, the opposite of what I described above as being "inspired" as were the writers of scripture-- being 'filled with the spirit' and having 'the word of God come upon you' -- these are all wordy ways of saying the same things. For good, or evil-- we are all to some degree, 'under the influence.' It works the same for these fallen ones, with the exception being who sends whom. Just as the elohim in the divine council above had/have a Chief-- there is one who sought to displace him and that one is Chief here-- I think of him as the Warden, where the insane are running the asylum.
The function of a devil is to accuse the guilty. The great metaphor of the universe is not a prison... it's a courtroom. These are the plaintiffs, and their function isn't necessarily evil. Man calls it evil because it rarely works in our favor. It is only truly evil when the accusation is false.
And this "warden" you speak of, the Father of Lies, was defeated long ago. The gates of Hades did NOT prevail to keep Jesus out, and He has set the captives free. Jesus now reigns, and I don't mean from far away as some sort of absentee landlord.
The gospel remains true - the kingdom of God is at hand. Here. Now. Our salvation is found in God's incarnation, not in man's disincarnation.