As we end the first chapter of masechet Sotah (and as discussed in our last post) we transition from discussing the punishment of the sotah to the reward for mitzvoth. The last example cited is that of Moshe who as reward for busying himself with Yosef's bones as the Jewish people left Egypt merited being buried by G-d Himself (Sotah 9b). 
"Rabbi Chama the son of Rabbi Chanina said: 'Why was Moses buried next to beit pe'or? So as to atone for the deed of pe'or'" (Sotah 14a). When we think of the sins the Jewish people committed in the desert it is the golden calf and the sin of the spies that come to mind. The first nearly caused the end of the covenant between G-d and the Jewish people and the latter led to the death of an entire generation in the desert. Yet possibly the most demoralizing of the sins was that of ba'al peor. Here we were forty years later about to finally enter the land and the Jewish people engage both in idolatry and sexual immorality (see Bamidbar 25:1-9). The brazenness of the people was such that the leader of the tribe of Shimon sinned openly and in public - despite his sin being an act one normally done in the most private of places. It is as if forty years in the desert had taught the Jewish people nothing. A great plague ensues wiping out 24,000 people - eight times the number who died for their worship of the golden calf. Most were from the tribe of Shimon[1]; people do take their cues from their leaders. So upset, perhaps disgusted is a better word, was Moshe that he refused to bless the tribe of Shimon on his "deathbed"[2]
G-d chooses to bury Moshe at Beit Peor to help effect atonement for the grave sins committed there. Left unexplained is the meaning of this cryptic teaching. Who exactly is being atoned for? Those who sinned and were killed in the plague long before Moshe died, the Jews in the desert who did not sin, the Jews today who have never been to Beit Peor? And how exactly does Moshe's burial effect atonement?  
Perhaps the answer lay in the immediately following teaching of the Talmud. "Rabbi Chama the son of Rabbi Chanina said: "What is the meaning of the verse, 'After the Lord your G-d, you shall walk' (Devarim 13:5)? Is it possible for a man to walk after the Divine Presence? Isn't it already stated, 'For the Lord your G-d is a consuming fire' (Devarim 4:24)? Rather, walk after the character traits of G-d" (Sotah 14a).
On the surface the link between these two teachings is the author of the statement, Rabbi Chama the son of Rabbi Chanina. In an oral tradition grouping together the teachings of a particular teacher - especially those who appear infrequentlyin the Talmud - makes eminent sense. Yet the Talmudic editors used much more than mnemonic devices in editing the Talmud. If not why not include his other teachings here - there are only three of them (Taanit 7b, 29 a and Makkot 10b - all in non-legal matters).
Idolatry is the antithesis of G-d and sexual immorality is the antithesis of G-d's moral code. Thus we often find these two prohibitions grouped together. This is the simple meaning of the Torah reading on Yom Kippur afternoon. "After the doings of the land of Egypt, where you dwelt, you shall not do; and after the doings of the land of Canaan, where I bring you, you shall not do; neither shall you walk in their statutes" (Vayikra 18:3). This admonition to avoid the idolatry of the Canaanites and Egyptians is followed by a listing of sexual practices practiced in those societies. In fact the Talmud (Sanhedrin 63b) teaches that the Jewish people only worshipped idols in order to permit sexual immorality; once we throw off the yoke of heaven all becomes allowed. 
When faced with ba'al peor whether in its ancient or modern versions one must double one's efforts to cling to G-d. We must walk in His ways - "Just as He clothes the too you shall clothe the naked. The Holy One, Blessed be He, visited the sick ... so too you shall visit the sick. The Holy One, Blessed be He comforted too you shall comfort mourners. The Holy One, Blessed be He, buried the dead... so too, you shall bury the dead."
The atonement for those who would deny G-d and His teachings is to embody those teachings in all that we do. There is nothing more fulfilling than walking in the ways of G-d. Moshe who came face to face with G-d and who brought us the Torah is our link to G-d allowing us to strive to follow in his example and enable us to gain atonement when we do stumble.  

[1] While the Torah never specifically states such it can be inferred from the fact the male adult population of the tribe Shimon declined from 59,300 to 22,200 in the years in the desert. Surely something went terribly wrong. 
[2] Sadly Yaakov too was upset at Shimon (and Levi) for their killing the people of Shechem. And while his message to them on his deathbed is more curse than blessings he at least spoke to them from his deathbed. There is nothing worse than being ignored.