A guest post by JS:
As DB is fond of pointing out, "Rashi is not an anthology of midrashim." Rashi carefully selects each midrash, gemara, and rabbinical statement in order to clarify a scriptural difficulty in a manner he deems satisfactory. If Rashi cites a midrash to resolve a grammatical error, the midrash not only irons out the difficult language to Rashi's liking, it also brings forth a concept that Rashi liked or at least didn't find untenable.
For example, in Shmot 2:5, Rashi is bothered by the phrase "וַתִּשְׁלַח אֶת אֲמָתָהּ וַתִּקָּחֶהָ" (and she [Pharoah's daughter] sent forth אֲמָתָהּ and took it [the basket containing Moshe]). Rashi first explains that the word אֲמָתָהּ means "her maidservant." However, he goes on to explain (and of course this is the only explanation anyone remembers) that the word אֲמָתָהּ means "arm" and is vowelized the way it is to indicate that her arm grew long enough to reach the basket. Therefore, in my opinion, Rashi cites the gemara to deal not only with the difficult language in the verse (why is אֲמָתָהּ vowelized the way it is) but also because he either liked the concept of a miraculously growing arm to reach the miracle-producing Moshe, or he didn't have a problem with that idea.
In this parsha, there are a couple of interesting Rashis from which emerge a picture of how Rashi conceived of Hashem (or at least how he didn't think it was sacrilegious to view Hashem). Please note what I just wrote in parentheses as, for the sake of clarity, I won't be repeating this again.
In BaMidbar 20:1 on the words "And Miriam died there," Rashi states that Miriam died just like her two siblings by a kiss from God's mouth. However, the verse doesn't say so because it is not respectful to speak of God in this way (as One who kisses women). Thus, Rashi believes that God, who wrote the Torah, didn't say the manner in which Miriam died because God was concerned His honor would be diminished if He said He kissed Miriam with His mouth.
In 20:12 on the words "Therefore, you shall not bring," Rashi states that "therefore" is a form of an oath and that God hastened to swear an oath that Moshe and Aharon would not take the nation into Israel because if He hadn't, Moshe and Aharon could have "beaten Him to the punch" and interceded with prayer, which He would have had to answer. Thus, Rashi believes that God can be forced into action by human beings and has to act quicker than they to avoid being coerced.
In 21:1 on the words "Who lived in the South," Rashi states that it wasn't actually the Canaanites who attacked Israel, rather it was the Amalekites disguised as Canaanites (as it is the Amalekites who lived in the South, not the Canaanites). Why did the Amalekites do this? Because if the Jews prayed "Save us from the Canaanites" their prayers would be worthless. But, the Jews were clever and only prayed generally saying "Save us" and therefore their prayers worked. Thus, Rashi believes that God is so demanding and specific in his answering of prayers that He would actually refuse to answer specific (but incorrect) prayers and thus, in order to have God respond to our prayers it's best to be general and non-specific.
Search for more information about Rashi at 4torah.com.