Luke, chapter 8:21, and Mark, chapter 3:33-35, have something similar, but Matthew is closer to Mark. Jesus made a distinction between his biological family and his new spiritual family. Jesus replied to the person who told him about his relatives (ὁ δὲ ἀποκριθεὶς εἶπεν τῷ λέγοντι αὐτῷ). He asked him who his mother was and who his brothers were (Τίς ἐστιν ἡ μήτηρ μου, καὶ τίνες εἰσὶν οἱ ἀδελφοί μου). He stretched out his hand pointing to his disciples (καὶ ἐκτείνας τὴν χεῖρα αὐτοῦ ἐπὶ τοὺς μαθητὰς αὐτοῦ). He said that they were his mother and his brothers (εἶπεν Ἰδοὺ ἡ μήτηρ μου καὶ οἱ ἀδελφοί μου). Anyone who did the will of his Father in heaven (ὅστις γὰρ ἂν ποιήσῃ τὸ θέλημα τοῦ Πατρός μου τοῦ ἐν οὐρανοῖς) would be his brother (αὐτός μου ἀδελφὸς), his sister (καὶ ἀδελφὴ), and his mother (καὶ μήτηρ ἐστίν). No longer was a biological family important, because there was now a new spiritual faith family of Jesus believers.
This verse of Matthew is similar to Luke, chapter 12:8-9, indicating a Q source. There is also something similar in Mark, chapter 8:38 and Luke, chapter 9:26, where it was more about being ashamed of Jesus. Everyone who acknowledged or confessed Jesus before other men (Πᾶς οὖν ὅστις ὁμολογήσει ἐν ἐμοὶ ἔμπροσθεν τῶν ἀνθρώπων), Jesus was also going to acknowledge or confess them before his Father in the heavens (ὁμολογήσω κἀγὼ ἐν αὐτῷ ἔμπροσθεν τοῦ Πατρός μου τοῦ ἐν τοῖς οὐρανοῖς). However, anyone who denied or repudiated Jesus before other men (ὅστις δ’ ἂν ἀρνήσηταί με ἔμπροσθεν τῶν ἀνθρώπων), he was going to deny or repudiate them before his Father in the heavens (ἀρνήσομαι κἀγὼ αὐτὸν ἔμπροσθεν τοῦ Πατρός μου τοῦ ἐν τοῖς οὐρανοῖς). Jesus wanted loyalty to him, no matter what the circumstances. If they were loyal here on earth, he would intercede with his Father for them in heaven, as their mediator.
This verse is somewhat similar to Luke, chapter 6:46. Matthew has Jesus say that not everyone who called Jesus Lord! Lord! (Οὐ πᾶς ὁ λέγων μοι Κύριε Κύριε) would enter the kingdom of heaven (εἰσελεύσεται εἰς τὴν βασιλείαν τῶν οὐρανῶν). Only those who did the will of his Father in heaven (ἀλλ’ ὁ ποιῶν τὸ θέλημα τοῦ Πατρός μου τοῦ ἐν τοῖς οὐρανοῖς) would enter the kingdom of heavens. It was not good enough to simply call Jesus the Lord, but you had to do the will of his Father to enter the heavenly kingdom,