In Matthew 5:20-44, Christ showed that obeying the “letter of the Law” is a matter of physical action, whereas obeying the “spirit of the Law” requires more than just outward actions—it also involves an attitude of the mind—referred to by the Apostle Paul as “circumcision of the heart” (Rom. 2:28-29).
For example, Christ showed that to merely refrain from adultery is obedience to the “letter of the Law,” but to obey both the spirit and letter of the Law, one must also exercise self-control (“temperance”–Gal. 5:23), and not even lust after someone (committing “adultery in his heart”).
Another example (not mentioned by Christ in Matt. 5) is in the keeping of the Sabbath Day. To merely “remember the Sabbath, to keep it holy” (Ex. 20:8), “not forsaking the assembling of ourselves together” (Heb. 10:25), is in obedience to the letter of the Law. But to also rejoice in the Sabbath and call it a “delight” (Isa. 58:13) is keeping the spirit of the Law, as God intends. This principle applies to all of God’s laws.