The Bible doesn't specifically tell us why God created the devil and the other demons. However, it makes clear that He has every right to do as He sees fit, given His perfect wisdom, perfect power, and perfect love.
The Book of Romans describes God's creation, including the devil and demons, as clay in the hands of the potter, and demonstrates by analogy that just as the potter has complete license over His creation, so does God over His.
Rom 9:21-24 - Does not the potter have power over the clay, from the same lump to make one vessel for honor and another for dishonor? What if God, wanting to show His wrath and to make His power known, endured with much longsuffering the vessels of wrath prepared for destruction, and that He might make known the riches of His glory on the vessels of mercy, which He had prepared beforehand for glory, even us whom He called, not of the Jews only, but also of the Gentiles? (NKJV)
Applying these verses to the devil and other fallen angels, it is entirely possible that God created them for the express purpose of making known the riches of His glory to those He has prepared for His mercy.
Good appears so much better when compared with evil.
The Bible further teaches that without regeneration by the Holy Spirit of God, each of us is likewise destined for destruction. Romans 3:23 tells us that all have sinned and fallen short of the glory of God. Romans 6:23 tells us that what we have earned from that sin is death. However, it goes on to say that the free gift of God is eternal life through Christ Jesus. Jesus Himself tells us in John 14:6 that He is the Way, the Truth, and the Life, and that no one comes to the Father but by Him.
According to Romans 10:9, if you confess with your mouth that Jesus Christ is Lord and believe in your heart that God raised Him from the dead, you will be saved.
If you have never accepted Jesus Christ as Lord of your life, now would be a good time to do so (2 Corinthians 6:2).
You are (1) referring to ontological equals, (2) neither of whom has perfect wisdom, perfect power, or perfect love.
Because of (1), yours is not a comparison of potter to clay, as the Bible makes, but of clay to clay, or potter to potter, so the analogy fails.
Because of (2), the glory of one's perfect wisdom, power and love will not be demonstrated by one who does not have them doing anything at all, including beating his child, hugging his child, or sending his child on a trip to the end of the rainbow. So again the analogy fails.
Thanks for your time, by the way.
If by knowledge of "religion" you would include knowledge of the Christian God, then there is no one who "knows nothing of religion" (Romans 1:20).
Also, it is quite impossible for Him to be anything other than absolutely perfect in every way. If He weren’t, reality would not be coherent:
God didn't recreate Himself when He made us. We are essentially nothing more than pots or jars of clay. Tools. Instruments. We are not autonomous, or on equal footing with our eternal God, and we never will be. We are merely created characters in a narrative.
But in this particular narrative, unlike most, the characters are actually aware of the Author. In fact, in a ridiculously absurd scene in this particular epic tale, one character, who seems in so many ways to be just like us, proves that He is not merely a normal character by first dying and then rising from the dead! And then by teleporting through walls! And by flying without wings! Walking on water! Raising others from the dead! Feeding thousands with a couple of fish! The rest of us haven't been able to do these things. This particular character claims that He can do these things because He is in some sense the author Himself!
These strange activities demonstrated evidentially that there was substance to His claims. He did these things, in large part, so that we could relate to Him (Hebrews 4:15; Philippians 2:6-8; John 3:16-17; 1 John 4:19).
In sum, we can relate to Him; everyone knows of Him; and He is necessarily perfect.
God did it and it worked marvelously:
And I (God) will put enmity between you (the serpent) and the woman (our ancestor), and between your offspring (Demons) and hers (US!!!); he will crush your head, and you will strike his heel."
If everything evil in this world is from Satan, and Satan is from God, and God made Satan evil, then all evil is from God with premeditation.
If Jesus is God, and if resistance to Jesus_the_God is from Satan; while Satan himself is from God, and purposefully made to be an enemy by God: then resistance to Jesus is from Jesus purposefully.
Thus both acceptance and rejection is what Jesus wants, BOTH! and He made it happen.
PURPOSEFULLY FROM GOD!
It's not an accident, it's an intentional $%-show of absurdity, and that is exactly the will of God.
We're all "Jobs" to whom God sent Satan to torture us.