The Torah records that upon nearing the end of his life, Yosef asks the other members of Bnai Yisrael to swear that when they leave Mitzrayim, they will take his bones out with them (בראשית נ:כ"ה). Many years later, as Bnai Yisrael were making their final preparations for Yetzias Mitzrayim, the Torah states that Moshe took Yosef's bones, the עצמות יוסף, with him (שמות י"ג:י"ט). The Gemara in Sotah (דף י"ג.) remarks that we can see from here how beloved Mitzvos were to Moshe Rabbeinu, because while all other members of Bnai Yisrael were busy with the ביזה, the spoils of Mitzrayim, he involved himself in the Mitzvah of taking Yosef's bones.
Commenting on the Midrash in Shemos Rabbah (פרשה כ' סימן י"ז) where this point about Moshe Rabbeinu is also made, the Eitz Yosef (שם בד"ה חכם) notes that Chazal seem to imply that even the most righteous Jews, the greatest בעלי אמונה, conducted themselves improperly here. Instead of involving themselves with the Mitzvah of taking out עצמות יוסף, they were preoccupied with amassing a large collection of booty. Clearly, Hashem had commanded Moshe Rabbeinu earlier to tell the people to take gold and silver from their Egyptian neighbors (שמות י"א:ב). Beyond a shadow of a doubt, many members of Bnai Yisrael considered their actions in taking this ביזה to be a fulfillment of this Divine commandment. However, the Eitz Yosef claims, their efforts to empty Mitzrayim of all its wealth, as the Posuk later says they did (שם י"ב:ל"ו), prompting the Gemara in Berachos (דף ט:) to say "עשאוה כמצולה שאין בה דגים," they made it like a pond without any fish, far exceeded their command. Many of the greatest Tzaddikim of that time mistakenly concluded that being involved in the ביזה, the booty, was a Mitzvah which outweighed the Mitzvah of taking the עצמות יוסף.
Rav Henach Leibowitz, in his Sefer חידושי הלב, explains that this situation exemplifies the crafty behavior of our Yeitzer Hora. One of the most basic elements in human psychology is the interaction between the brain and the heart. Every person wants to believe that his decision making process is free from any bias or emotional influence. In fact, it is quite possible to find well-educated individuals who adamantly refuse to analyze their own actions, and take a חשבון הנפש to honestly evaluate the real motives for their deeds. Yet almost every assessment we reach is influenced by our emotions and by our personal prejudices. The Yeitzer Hora, in fact, rarely attacks with a "frontal assault," to persuade us to sin in order to simply satisfy our physical wishes. Rather, the Yeitzer Hora tries to camouflage his goal by presenting the Aveirah in the guise of a Mitzvah. Undoubtedly, Bnai Yisrael began their collection of gold and silver לשם שמים, to fulfill Hashem's commandment. In the process, however, the Yeitzer Hora clouded their vision and enticed them to procure additional wealth for personal gain. Instead of assisting Moshe Rabbeinu with the עצמות יוסף, they convinced themselves that their quest for riches was of equal spiritual value.
Remarkably, even the greatest Tzaddikim can manipulate their minds to commit Aveiros. Although Shmuel HaNavi had informed Shaul HaMelech that it was prohibited to keep any spoils from the battle with Amalek, Shaul notified Shmuel that he indeed had taken cattle in order to bring sacrifices to Hashem (שמואל א' ט"ו:ט"ו). The Radak (שם) suggests that Shaul claimed he was innocent of ignoring Shmuel's orders because his intent to slaughter those animals as Korbanos was לשם שמים, and not for any personal gain. But Shmuel subsequently informed Shaul that it was actually his desire for affluence that cajoled him towards this rationalization that he was performing a Mitzvah. The brilliant mind of Shaul HaMelech had been convinced that the word of Hashem did not apply to him; he thus persuaded himself that it was correct to disregard the spiritual leader of his generation and to execute an action which defied Hashem.
The Torah will often magnify a "sin" perpetrated by our righteous ancestors which in reality was merely a minute mistake in judgement that by our standards would not even be classified as an Aveirah. Tzaddikim, due to their lofty stature, are judged very strictly. But if they can be influenced sometimes by inappropriate emotions, we, on our own level, can certainly be so detrimentally influenced. One can believe with deep conviction that he is involved in a Mitzvah, such as offering a sacrifice to Hashem, while in truth he is acting only to satisfy his desires. Even a righteous man can delude himself into demeaning a great Torah authority as he pursues what he considers his "spiritual" goals. We must all constantly check our motivations, and explore the roots of our actions. With this approach, we can ensure that all our actions are indeed solely לשם שמים.