Although the tzaddik is utterly free of the internal inclination to evil that plagues the ordinary man, he is not devoid of free will.
As long as he is in the human realm, he is free to choose, and he is liable even to err and choose wrongly.
Moreover, there are situations in which there is a fault to every available option.
These are faults that do not arise from within the tzaddik but are inherent in the situation itself.
Moses is recorded as having lost his temper on a number of occasions.
Moses' anger was certainly a fault, yet the situation made it impossible for him to act otherwise.
Anger was the only educational means available to correct the problem.
The prayer for rain recited on the festival of Shemini Atzeret is composed of verses mentioning the deeds of the leaders of Israel in connection with water.
The verse in praise of Moses is that "He struck the rock and water emerged."
But was not striking the rock the sin of Moses' life, for which his punishment was that he could not enter the land of Israel?
In his commentary on Torah, Rashi explains Moses' sin: if Moses had spoken to the rock rather than struck it, this, would have been a great lesson for the people of Israel.
The people would have said, "If the rock, which is deaf and dumb and does not require sustenance, obeys Moses, then we certainly must obey him."
Yet Moses did not want to speak to the rock; he knew that if the Jewish people continued to disobey him, even after witnessing the rock's obedience, this would have constituted a great accusation against them, against which there could be no defense.
So, instead of speaking to the rock, he struck it.
Moses, who was close to God more than anyone else before or since, also faced choices.
He chose, mistakenly or not, to do something that was counted against him, on the one hand, as his great sin, and counted to his credit, on the other, as one of the great deeds of his life–that "He struck the rock and water emerged."
Situations arise in which perfection is not possible, in which the very structure of reality and the relation between a person, the world, and God are such that no perfect solution exists.
In such a situation, even a tzaddik can reach an erroneous decision.
King David's sin with Bathsheba was a tragedy for Uriah, for David, and for Bathsheba, but from the greater perspective of Jewish history, it gave rise to one of the greatest moments of teshuvah ("repentance").
Virtually every person sins, and when a sinner reads Psalm 51, "When Nathan came to him [David] after he went to Bathsheba," he has something to relate to.
Considering that David is the fourth leg of the "divine chariot," David's sin might be the only way in which certain people can relate to him.
If the great ones of Israel had no faults, it would be impossible to establish any connection with them.
In this sense, their falls are our path to elevation.
In our reality, we face problems with no clear, unambiguous solution.
The question of whether something is a mitzvah or a sin, or a mitzvah best neglected, or a sin that it is perhaps necessary to commit, does not always have an answer.
–Rabbi Adin Steinsaltz
From Opening the Tanya, p. 251, by Rabbi Adin Steinsaltz