The term “such knavish imbecility” might be slightly exaggerated for a shock effect.
However, in the Church there is the human element alongside with the Divine. The human element is constantly assisted and supported by the Divine, and that’s how the gates of the netherworld are unable to prevail.
There are a lot of human things that have been with us for a long time yet their existence does not automatically denote divine approval.
What evidence do you have that the gates of hell are not prevailing against the church? Because when someone looks at the condition of Catholicism today, and throughout much of its history, it isn’t faring so well.