From The Gospel of Matthew, by Curtis Mitch and Edward Sri, commenting on Matthew 16:13-20
Several indicators, including the metaphor of a building, suggest that Jesus envisions his Church as a temple of believers (as do other New Testament texts; see 1 Cor 3:16–17; 2 Cor 6:16; Eph 2:19–22; 1 Pet 2:4–6).
The expectation of a messiah that was shaped by the oracle in 2 Sam 7:8–17 held that the coming son of David (royal messiah), like the original son of David (King Solomon), would construct the house of the Lord in the midst of his people (2 Sam 7:13; also Zech 6:12–13). Peter’s confession of Jesus as Messiah thus entails the expectation that he will build the Lord’s temple in the age to come.
A second indication that the rock imagery is connected to the building of a temple lies in Jesus’ statement that the gates of the netherworld shall not prevail against his Church.
In the symbolism of Israel’s theology, the gates of the netherworld were the opening leading down to Hades, also called Sheol, or the Pit, which was the dark and gloomy underworld hidden deep within the bowels of the earth. There the souls of the dead sank down into a shadowy, joyless existence. There also, in Jewish thinking, was the habitation of infernal powers that bring death and deception into the world of the living (see Rev 9:1–6; 11:7; 20:1–3).
Later, rabbinic Judaism believed that the foundation stone of the temple capped off the shaft leading down to the underworld. Peter is now given a comparable role in the living temple built by the Messiah. Thanks to the blessing of Jesus on Peter, now made the rock of the new temple, neither death, nor the devil, nor his deceiving spirits shall ever prevail against the Church.