It is interesting to notice that 'your righteousness must exceed that of the Pharisees' has two legitimate meanings:
1, practically, it should be and this is illustrated 7 times in Mt 6.
2, as far as justification goes, there is no question, because they really were failures.
So back in Mt 3, we see the baptism of (not by) Jesus, and he said it was necessary to fulfill all righteousness. So we know that he had to complete what God wanted for righteousness, and that does not just drift into believers, although it should. The entirety of it is the perfect completing of the law of God and can only be credited against the debt of sin.