Shemot1:17

וַתִּירֶאןָ הַמְיַלְּדֹת אֶת־הָאֱלֹהִים וְלֹא עָשׂוּ כַּאֲשֶׁר דִּבֶּר אֲלֵיהֶן מֶלֶךְ מִצְרָיִם וַתְּחַיֶּיןָ אֶת־הַיְלָדִים׃

But the midwives feared the Almighty and did not do as the king of Egypt had told them, and they kept the boys alive.

Shemot 1:17

וַתִּירֶאןָ הַמְיַלְּדֹת אֶת־הָאֱלֹהִים

Shemot / Exodus 1:17 · Drash

Shemot 1:17

וַתִּירֶאןָ הַמְיַלְּדֹת אֶת־הָאֱלֹהִים וְלֹא עָשׂוּ כַּאֲשֶׁר דִּבֶּר אֲלֵיהֶן מֶלֶךְ מִצְרָיִם וַתְּחַיֶּיןָ אֶת־הַיְלָדִים׃

But the midwives feared the Almighty and did not do as the king of Egypt had told them, and they kept the boys alive.

Drash דְּרָשׁ

As she spoke to Yosef

"They did not do as the king spoke to them." The Torah could have written "as he said to them", but wrote "as he spoke" (כַּאֲשֶׁר דִּבֶּר). The midrash compares these words with the story of Yosef (Joseph) in Potiphar's house.

Midrash Lekach Tov: see how great the fear of Heaven is: the Torah testifies to it in the midwives, and Moshe and Yeshayahu (Isaiah) both call it the main thing. And Rabbi Yose bar Chanina teaches: "as he spoke" is the same word as "as she spoke to Yosef day after day". As there it was about sin, so here: Pharaoh pressed the midwives to sin, and they did not yield.

How Midrash Lekach Tov explain it

Midrash Lekach Tov And the midwives feared the Almighty

Come and see how great the fear of Heaven is. For Scripture testifies of the midwives: "and they feared". And Moshe said: "what does the Eternal your Almighty ask of you? Only to fear the Eternal" (Devarim / Deuteronomy 10:12). And Yeshayahu says: "the fear of the Eternal is His treasure" (Yeshayahu / Isaiah 33:6). And many like these.

Midrash Lekach Tov And they did not do as the king of Egypt spoke to them, and they kept alive

It should have said "as he said to them". What is "as he spoke to them"? But Rabbi Yose bar Chanina said: this teaches that he pressed them to sin, and they did not yield. It is written here "as he spoke", and it is written there: "as she spoke to Yosef day after day" (Bereshit / Genesis 39:10). As there it is about sin, so here it is about sin.

Takeaway

Gezerah shavah (גְּזֵרָה שָׁוָה), "equal decree": the midrash links two places in the Torah through one word and carries the meaning from one to the other.
"As she spoke to Yosef day after day" is Potiphar's wife, who pressed Yosef to sin (Bereshit / Genesis 39:10). Yosef stood firm, and here the midwives stood firm in the same way.