What is the connection between this Pasuk, the previous one and the following one?
Rashi: Moshe refers to the sin of Ba'al Pe'or, to point out to the people that, although his sin was not forgiven, their sin stands to be forgiven (and they will enter Eretz Yisrael), provided they obey Hashem's Mitzvos, as the Pasuk goes on to inform them.
Ramban: Refer to 4:5:1:1.
Seforno: The sequence of the current Pesukim runs as follows: Now that you see that Hashem is prepared to send you into exile in the event that you sin, 1 take care to observe His Mitzvos without adding to or subtracting from them, not even if the reason behind the Mitzvah no longer applies. 2 Because the slightest deviation from the Mitzvos brings destruction in its wake - like what happened by Ba'al Pe'or, where the people thought that they would just commit adultery 3 with the Mo'abite women without worshipping their idols. 4 But to no avail! In the end all those who began by committing adultery with the Mo'abite women ended up by wotshipping Avodah-Zarah and were wiped out.