My study of fasting in Scripture taught me two things. 1) If you want to fast as a religious ritual, do it from a heart that is expressing a genuine faith and sincere desire to know and love God; and 2) Don’t use fasting as a test to reject your fellow believers and/or impress other people.
In these stories, Jesus challenges the religious culture and practices of the Pharisees, not the Old Testament. His understanding is so fundamentally incompatible with the Pharisees that if he tried to reform their their views, he would only destroy them.
Being religious is no guarantee that you are genuinely following God. Whatever you define as obedience to God (being in full-time ministry, church attendance, praying, fasting, giving to the poor, adopting social justice causes), Jesus says: stop and ask yourself who are you doing it for?