Zachor es asher osah lecho Amalek baderch be’tzaischem mi’Mitzrayim”—Remember what Amalek did to you on the way, when you were going out of Egypt” (Bamidbar 25:27).
It is written: “Zachor es Yom HaShabbos le’kodsho” and also ”Zachor es asher osah lecho Amalek.” How can the command form of the verb, “zachor” be used in reference to both Shabbos and Amalek? A cup of Konditon wine is not like a cup of vinegar, although the noun “cup” is used to describe the containers of both? In a similar vein, one “zachor” pertains to “lekadesh” ─ to sanctify, and the other to destroy and kill (Yalkut Shimoni)?
So how are the two connected?
Based on the verse “Va’yavo Amalek va’yilachem im Yisrael be’Refidim”—Amalek came and fought with Yisroel in Refidim” (Shemos 17: 8), Chazal say that the war with Amalek occurred because they slackened in their Torah study.
During the week, most people spend the majority of the day engaged in earning a living. It is only on Shabbos that they have time to engage in Torah study. Studying Torah and engaging in ruchniyus is the major goal of Shabbos.
The medrash explains that the connection of the two zechiros is to stress that we must recall that Amalek attacked us because we slackened in our Torah study which can be rectified by remembering the Shabbos to sanctify it. In other words by sanctifying Shabbos through Torah learning, and that this is what prevents Amalek from attacking us.