The "gates of hell" passage means that His Church will never be destroyed and will never fall away from Him. His Church will survive until his return. If the Church abandoned Christ's message (doctrinal error), or changed it on the whim of some individual(s), would it not, in a very real sense, fall away from Christ?
See 1 Tim 3:15, where St. Paul refers to the Church as the "pillar and foundation of truth."
It's a simple statement, Death will not prevail over the church.
With that said, any of us can springboard off of that into whatever doctrine we've a notion to proclaim, and give that as our foundation.
"The gates of hell will not prevail over the church, so there will never be divorce within the church. Because divorce separates the body from the head, which brings death, and death will not prevail. Paul teaches marriage as portraying the body of Christ."
OK, I just made that up, and I'm not good with hypotheticals because they are not real. I like real things. Just the same, I hope you see my point.
This passage,
Matthew 16:15-21 KJV
15) He saith unto them, But whom say ye that I am?
16) And Simon Peter answered and said, Thou art the Christ, the Son of the living God.
17) And Jesus answered and said unto him, Blessed art thou, Simon Barjona: for flesh and blood hath not revealed it unto thee, but my Father which is in heaven.
18)
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.
19) And I will give unto thee the keys of the kingdom of heaven: and whatsoever thou shalt bind on earth shall be bound in heaven: and whatsoever thou shalt loose on earth shall be loosed in heaven.
20) Then charged he his disciples that they should tell no man that he was Jesus the Christ.
21) From that time forth began Jesus to shew unto his disciples, how that he must go unto Jerusalem, and suffer many things of the elders and chief priests and scribes, and be killed, and be raised again the third day.
This statement in vs. 18 ". . . I will build my church, and the gates of hell will not prevail against it" doesn't make any statement concerning the church in an active sense, and does not specify how it will be that 'the gates of hell' - death - will not prevail over it. This is a propositional statement with a clear set of sayings. Jesus builds the church. It's His church. Death will not conquer it.
One passage that comes to my mind thinking about this is in Peter,
1 Peter 1:3-5 KJV
3) Blessed be the God and Father of our Lord Jesus Christ, which according to his abundant mercy hath begotten us again unto a lively hope by the resurrection of Jesus Christ from the dead,
4) To an inheritance incorruptible, and undefiled, and that fadeth not away, reserved in heaven for you,
5)
Who are kept by the power of God through faith unto salvation ready to be revealed in the last time.
Here, God is guarding us by His power, but the mechanism isn't doctrine, it's faith.
Another passage that comes to mind,
1 John 5:2-5 KJV
2) By this we know that we love the children of God, when we love God, and keep his commandments.
3) For this is the love of God, that we keep his commandments: and his commandments are not grievous.
4) For
whatsoever is born of God overcometh the world: and this is the victory that overcometh the world, even our faith.
5)
Who is he that overcometh the world, but he that believeth that Jesus is the Son of God?
Here, faith again is the answer, faith in Jesus Christ.
Much love!