Matthew 7 emphasizes our relationships with others. The first lesson (v. 1) teaches us not to judge other servants of the Master (compare Romans 14:4). There certainly are times when we should judge, as in Matthew 7:16 or 1 Corinthians 6:1-2. But in this context, we do not judge.
This verse is often applied to judging the motives of others, which we can never do. Motives are not plain to us, and we often make wrong assumptions. Only God knows the heart.
The Word of God reveals to our own selves the intents of our hearts (Hebrews 4:12), but we are not to try to imagine the intentions of others.
Another connection would be James 4:11, in which we are warned not to speak evil of our brother, particularly about issues that the Scriptures don't address. Doing so shows our pride, as if we are actually judging God's word for not addressing those issues.
In the context of Matthew 7, we are not to judge because the critical standard we apply in judgment will actually be applied to us. Consider the case of David, who had sinned by taking another man's wife and then arranging the man's death. When the prophet Nathan told a parable about it, David pronounced judgment on the selfish man in the story. Then Nathan said, "You are the man" (2 Samuel 11-12).
Romans 2:1-3 warns against judging others and then doing the same things ourselves, which is often the case. We can't judge accurately because we have not dealt with the evil in our own lives. While we are obsessed with noticing the "speck" in another person's eye, the Lord says to us, "Look, a plank is in your own eye! (Matthew 7:3-4). He expects us to be attentive to our own behavior before we try to help others.
The hypocrites in chapter 6 were unbelievers, but here even a believer is a hypocrite (7:5). Imagine the lack of sensitivity in not knowing that a beam is in your own eye! We would not want the help of an eye doctor who himself could not see clearly because of such impaired vision.
This does not mean correction of others should never be done. After we remove the beam and see clearly, we should be willing to help if it turns out there really is a speck in our brother's eye (7:5). Even then, it will not be received well if my only interactions with that brother are to point out his "specks."
Verse 6 talks about keeping precious things away from "dogs" and "pigs." These were unclean animals to the Jewish people, and they represent scoffing unbelievers today. We don't try to force spiritual truths on those who reject them. The owner of these "pearls" is throwing them down; he doesn't seem to appreciate their spiritual value, either.
Next, in answer to the daily worries of chapter 6, the Lord describes a healthy prayer life (7:7-11). We keep on asking, seeking, and knocking. There may be repetition of these requests, but they are heartfelt, not empty as in 6:7.
Prayer is not a blank check. We can count on our Father to give good things to us; and He likes us to ask, as well (v. 11).
The right path is a narrow one, and it may be lonely because not many travel it. Yet it leads to life (7:13-14).
In the concluding words of the Lord's message, we ask ourselves, "Where is our foundation?" (7:24-29). There are many things upon which to build, but only the Lord Jesus and His teachings are solid rock. The key thing is to do what He has said (v. 24).
His closing shows that He had given the final word. Nothing comes after Him to add or detract. Not even the learned scribes spoke with the authority that He had.
At the Lord's birth, there were wise men who came from the East to bring Him their treasures. If we listen to the Lord ourselves, we can be wise men, too (7:24).