What do we learn from "Shomer Mitzvah Lo Yeda Davar Ra"?
Torah Temimah citing Shabbos 63a: Anyone who does a Mitzvah the way it was commanded will not hear bad tidings. Even if Hashem had made a harsh decree on him, He will tear it up. The previous verse says "ba'Asher Devar Melech Shilton u'Mi Yomar Lo Mah Ta'aseh."
Rashi: If you guard a Mitzvah, you will not know evil, and it will not come upon you. Ibn Ezra #1 - this applies most of the time.
Ibn Ezra #2: One who guards a Mitzvah, he does not want to know a bad matter (sin).
Ri Kara: One who guards the kingdom's laws, they do not find sin in him, and do not punish him.
Ri Kara (6): One who guards Hashem's Mitzvos, they do not make an evil decree on him.
Seforno: One who guards and contemplates Hashem's Mitzvos will not find Ra, i.e. lack of nice purposes.
Metzudas David: If he transgresses the king's word in order to guard a Mitzvah of Hashem, he will not be in danger. Hashem will protect him.
What do we learn from "v"Es Mishpat Yeda Lev Chacham"?
Rav Sadya Gaon: A Chacham knows the time and conduct proper for every matter. Ibn Ezra - this connects to the coming verse.
Rashi: A Chacham knows that there is a fixed time for punishment of Resha'im. There is Mishpat in front of Hashem which will exact payment from the Rasha in the end. Ri Kara (6) - therefore, he refrains from sin.
Ibn Ezra #1: Some say that here, "Es" is like Chachmah 1 , and similarly "La'us Es Ya'uf Davar" (Yeshayah 50:4), "b'Yad Ish Iti" (Vayikra 16:21), "Yode'ei ha'Itim" (Esther 1:13), "Yode'ei Vinah la'Itim" (Divrei ha'Yamim I, 12:33).
Rashbam: A Chacham knows that the time of punishment comes to the world, therefore he guards His Mitzvos.
Ri Kara: A Chacham knows to guard himself at all times, and knows the Mishpat (law) of one who rebels against the kingdom, and is careful not to transgress the kingdom's commands.
Seforno: He knows and understands the time when Mitzvos and Mishpat were given, and the reason why they were given.
Metzudas David: Even though one should not rebel against a Mitzvah of Hashem, not all times are the same. Sometimes the time requires doing so to heed the king, for a fence. Sometimes etiquette of the kingdom enacts a custom 2 on the entire kingdom, and it is proper to heed it, even if it is to transgress a Mitzvah, for Dina d'Malchusa Dina 3 . A Chacham knows when it is proper to do so, and when it is proper to follow etiquette of the kingdom.
Ibn Ezra: This is wrong. "La'us" it to make a time, like the verse continues "Ya'ir ba'Boker ba'Boker." "Ish Iti" is designated to go at that time; he will not delay. Or, he normally goes at all times of the year to that Midbar. "Yode'ei Vinah la'Itim" - they likewise to calculate when to make leap years (Bereishis Rabah 72:5). "Yode'ei ha'Itim" are [Chachamim of] the Mazalos.
Metzudas Tziyon: Mishpat is custom, like "u'Mishpat ha'Kohanim" (Shmuel I, 2:13. He did not cited "Mishpat ha'Kohanim" (Devarim 18:13) for that is a Chiyuv [to give Matanos from a Chulin animal to a Kohen]. - PF)
Shach (CM 73): Even those who say that Dina d'Malchusa applies to matters between people, this is not if it opposes Torah law! Metzudas David requires investigation. (PF)