What exactly did Jesus mean when He closed this section of the Sermon on the Mount with, “You are to be perfect, as your heavenly Father is perfect” (Matthew 5:48 NASB)?

The law itself demands perfection (Leviticus 19:2; 20:26; Deuteronomy 18:13; 27:26; James 2:10). Obviously, Christ set an unattainable standard. Though this standard is impossible for fallen sinners to meet, God could not lower it without compromising His own perfection. He who is perfect could not set an imperfect standard of righteousness. Since no sinner can possibly live up to that standard, we are dependent on grace for salvation. Our own righteousness can never be good enough (Philippians 3:4–9); we desperately need the perfect righteousness of Jesus Christ that God imputes to those who believe (Romans 4:1–8). That is the marvelous truth of the gospel: Christ has met this standard on our behalf.