Rashi’s commentary is composed, for the most part, of adapted midrashim. What motivates Rashi to turn to midrashim that apparently do not explicate the peshat?
A difficulty in the verses that has no reconciliation with the peshat.
The Torah does not speak in the human vernacular. Rashi adopts R. Akiva’s approach, according to which every word has meaning and significance. Therefore, one should be precise with biblical language, and even when the reader has no difficulty understanding the verses, one may derive information from some extraneous element in the text.
Maintaining the internal logic and sequence of the text by filling in lacunae.
When the verse and its midrash constitute excellent opportunities to transmit a spiritual or ethical message, Rashi cites the midrash even though there is no exegetical need for it.