Did you ever think you would find this in the Bible? It seems to advise a middle-of-the-road approach to righteousness, but to take it at face value is impossible, given all that the Bible says about striving after holiness. He is talking about self-righteousness which kills the soul.
Self-righteousness shows itself in good works which are done before men, including prayer, fasting, the giving of alms. This person does not really believe in a reward that comes from God, and so he seeks the only reward he knows about – human admiration of his righteousness – and Christ tells us that he receives his reward in full. In other words, he has received everything he is ever going to get, because God is repulsed by his so-called good works.