Parshat Vayelech 5780

Devarim 31: 6
Be strong and of good courage, be not in fear of them; for the LORD your God Himself marches with you: He will not fail you or forsake you.
 
Be strong and have courage is repeated three times in the parsha, including after the next verse.
 
Devarim 31: 17-18
… My anger will flare against them, and I will abandon them and hide My countenance from them. … And they shall say on that day, “Surely it is because our God is not in our midst that these evils have befallen us.” Yet I will keep My countenance hidden on that day, because of all the evil they done turning to other gods.
 
Psalm 27:14 (Rabbi Adin Steinsaltz, trans.)
Wait for God; be strong and take courage, and wait for God.
 
Can you reconcile the two thoughts? On the surface, the first statement occurs in the context of the upcoming battle, while the second thought regards the time when the Israelites break the covenant by worshiping other gods.
 
Sforno
all of this befallen me because God has abandoned me. Seeing that they feel abandoned, they will not bother to pray to Me, nor will they do teshuvah, considering such prayer futile, wasted 
not as they thought that I was no longer in their midst; wherever they are My presence is with them as our sages said in Megillah 29[a] “wherever the Jewish people have been exiled God’s presence accompanies them. However, it does not manifest itself by saving them from their oppressor.”
 
Sforno initially says that the abandonment is from the Israelites, not God — they aren’t trying to reconnect. How do you understand his second comment? The text in the Talmud, cited by Sforno, describes multiple stories of sages finding comfort in the synagogue and study hall in the midst of exile.
 
Rabbi Adin Steinsaltz
… Moses is proving the Jewish people the ability to bear difficulties in the future … Here Moses tries, difficult as it may be, to prepare the people in advance for the descent. … he does not mean to frighten them but to prepare them for the reality that life is full of ascents and descents. … the Torah is optimistic, in it that it shows the possibility of rectification [teshuvah], but at the same time, it makes clear how challenging this can be.
The same idea appears in Psalms 27, which we recite during the month of Elul and the Days of Awe … Before the problems begin, “wait for God.” After the problems are over, “wait for God.” And in between, “be strong and take courage.”
The command to take courage means not being shaken by problems and not being shattered by troubles, because breaking down in the face of problems is the most dangerous thing one can do.
The repeated and emphatic use of the expression “be strong and of good courage” is a call not only for courage in the colloquial sense, but also for a tenacious effort to hold on tightly and steadfastly to one’s faith. The secret to serving God is resilience: “Seven times the tzaddik falls and gets up.” (Prov. 24:16).  What characterizes the tzaddik is not that he does not fall but that after the fall he gets up.
To fall is part of life, but to be cast down need not be. … When a person commits a sin, he is liable to become broken, torn, and devoid of courage. If this happens and, as a result, the sinner collapses, he can no longer return. 
Parashat Vayelech says that whether you fall or not, whether you become corrupt or not, no matter what happens – “be strong and take courage.”