I think in part it is a mystery, but there is a general answer: of course, God foresaw the fall of the angels. And he knew that their fall would be irredeemable. For the angelic intellect is unimpeded by physical steps. After the revelation, the angelic intellect is able to comprehend the whole plan of the physical creation and understand it completely, so that the first choice of the angel is its last. And, admitttedly, the allowance of demonic influence in Salvation is not something that God could not help, as if Christ would say, “my hands are tied, I couldn’t stop the devil from tempting if I wanted to.” No, God is only allowing demonic activity in order that, as one poster put it, that He may draw a greater good from it.
And the ultimate greater good is that another type of fallen creature might be restored to love and then go on to love God and other creatures in a GREATER way than if he had never fallen to begin with. In short, something (suffering) that entered the human condition precisely because of human fault has been transformed so as to have the potential to be something proactively redemptive rather than punishment, that is, redeemed human creatures can now unite their sufferings with Christ and merit graces for others.
Yes, the dragon has seven heads and ten horns, the exact anatomy as the beast, for as the beast symbolizes the ages of sin across all of salvation history, so then the dragon and his forces are precisely those that have instigated these ages of sin in the human drama. And yet, in each successive stage, God “slays” the respective heads of the beast through great acts of Redemption that draw a greater good from the sin than if the sin had never occurred to begin with.
Consider a perennial example, the persecutions of pagan Rome. For no sooner does Christ ascend than the dragon wages war to prevent the conversion of the world. He “accused” the Christians of being cannibles and insurrectionists and orchestrated the worst persecution of the Church ever, and yet it back-fired. For precisely by the witness of the fearless and great courageous men, women, and even children, who endured unthinkable tortures out of love for God, the paganism of Rome fell and Christianity triumphed. For the witness of love and courage of the martyrs glorified God in a way that is far greater than if man had never fallen. That is, the glory of the power and grace of God shining through human weakness, in the moments of unspeakable pain, shows a love and beauty that glorifies God infinitley more than if Adam and Eve had never fallen.
Also consider the mystics’ take on what God will do with our mess. For we can surmise that even after the dragon was cast out of heaven to earth, he said to God, “OK, I wasn’t able to stop the conversion of the Gentiles, but I can undo it. I can create a religious can of worms over the next 1700 years, forming religious factions and gray areas and confusion and scandal so that when I’m done, the world will actually lose the faith nearly altogether”. And God says, “OK, fine. Go ahead! Because I’ll use it for a restoration. Indeed, go ahead and divide my children. For when the world finally becomes apostate, they’ll experience the consequences of all the errors you propogate, they’ll see the darkness for what it is, and they’ll reembrace the light, all of it, and when they do, there will truly be a Sabbath rest ,my will WILL be done on earth as it is in heaven.”