Matthew 16:18 KJV And I say also unto thee, That thou art Peter, and upon this rock I will build my church; and the gates of hell shall not prevail against it.
"Hell" is a translation of "Hades" which is not the lake of fire, the final place of the reprobate, but is a place of waiting for judgment. Before the Crucifixion it would seem that the elect were held in a separate section of Hades. Their sins had been covered but not yet taken away.
Ephesians 4:8-10 KJV Wherefore he saith, When he ascended up on high, he led captivity captive, and gave gifts unto men. (9) (Now that he ascended, what is it but that he also descended first into the lower parts of the earth? (10) He that descended is the same also that ascended up far above all heavens, that he might fill all things.)
This is one of the passages which depicts the human soul of the Lord descending into Hades after the Crucifixion. But He had the power to take up His life (literally "soul") (John 10:17-18) and ascend to Heaven. Where the first Adam was a living soul, the last Adam became a life giving spirit (1st Cor. 15:45).
And the gates of Hades could not prevail against Him. They were broken from the inside, not the outside as many assume.
The captivity "led captive" would seem to be the elect that had died prior to the Crucifixion. Their sins which had been covered were now taken away by the blood sacrifice of the Cross.
The context of the quotation in Ephesians clearly shows the application to the faithful remnant of Israel:
Psalms 68:6 KJV God setteth the solitary in families: he bringeth out those which are bound with chains: but the rebellious dwell in a dry land.
Psalms 68:18-20 KJV Thou hast ascended on high, thou hast led captivity captive: thou hast received gifts for men; yea, for the rebellious also, that the LORD God might dwell among them. (19) Blessed be the Lord, who daily loadeth us with benefits, even the God of our salvation. Selah. (20) He that is our God is the God of salvation; and unto GOD the Lord belong the issues from death.
Psalms 68:22 KJV The Lord said, I will bring again from Bashan, I will bring my people again from the depths of the sea:
The reason that captivity is led as still captive is that they are still naked souls, without personal spirits. Although now completely redeemed they can only rise to heaven with the Lord's assistance.
The loss of the personal spirit at death for the reprobate always, and for all before the Crucifixion and Resurrection is shown:
Ecclesiastes 12:7 KJV Then shall the dust return to the earth as it was: and the spirit shall return unto God who gave it.
Luke 23:46 KJV And when Jesus had cried with a loud voice, he said, Father, into thy hands I commend my spirit: and having said thus, he gave up the ghost.
All of the captivity seem to receive a new spirit in heaven. Some of this is shown symbolically in Revelation.
Revelation 6:11 KJV And white robes were given unto every one of them; and it was said unto them, that they should rest yet for a little season, until their fellowservants also and their brethren, that should be killed as they were, should be fulfilled.
But the Church would seem to participate in the Lord's triumphant exit through the gates of Hades in a better manner.
Colossians 2:11-13 KJV In whom also ye are circumcised with the circumcision made without hands, in putting off the body of the sins of the flesh by the circumcision of Christ: (12) Buried with him in baptism, wherein also ye are risen with him through the faith of the operation of God, who hath raised him from the dead. (13) And you, being dead in your sins and the uncircumcision of your flesh, hath he quickened together with him, having forgiven you all trespasses;
The members of His body having died with Him, have thus also been made alive together with Him. That is, their souls were taken up by a new eternal personal spirit, as His spirit took up His soul in Hades.
And thus joined to Him, the gates of Hades could not prevail against them.