Why did the King of kings, blessed be His name, the Holy One, Blessed is He, before Whom there is no favoritism, and Who examines the heart and tests emotions, bring the plague of darkness upon them? Because among Israel there were transgressors who had Egyptian patrons and who lived in affluence and honor, so they did not want to leave Egypt. The Holy One, Blessed is He, said: If I bring a plague upon them openly from which they will die, the Egyptians will claim, "Just as we were afflicted, so too were they (Israel) afflicted." Therefore, He brought darkness upon the Egyptians for three days; man could not see his fellow man, but all of the Children of Israel had light in their dwellings.
The Ten Plagues were given "measure for measure" as punishment for specific Egyptian wrongs, the midrash claims, and then goes through each and every one to explain which of Pharaoh's sins merited the particular plague in question. Interestingly enough, the last of the plagues—the death of the firstborn—is not discussed; presumably, it was the obvious answer to Pharaoh's killing of Israelite babies some chapters earlier. Darkness, then, is the last plague examined in this section and its explication is anything but intuitive.
Rather than identify a clear sin of the Egyptians that would merit the plague of darkness, the midrash turns the formula on its head. Darkness was given to provide a cover (albeit a scary, plague-ish one) for the real "measure for measure" taking place: the punishment of Israelites who, for selfish material reasons, did not want to leave Egypt. The exact nature of that punishment is not specified, but we infer that it is something terrible enough for God to want to cover up the act before the Egyptians, lest they come to equate the suffering (or death?) of the Israelite sinners with their own suffering and the death-to-come of their firstborn.
And so this midrash would have us believe that the Egyptians were not the only ones to suffer from the Ten Plagues. Israelite sinners were also punished, a sign (the midrash suggests) of God's justice. It would not have been fair for the Israelites who lacked faith to be redeemed along with their faithful brethren. It also would not have been fair for only the Egyptians to suffer via the plagues when there were sinful Israelites around, too. In envisioning darkness not only as a plague of divine retribution for the sins of Pharaoh, but as a cloak enabling divine retribution for the sins of the Israelites, we are given a hint that the God of Justice who produces the Exodus is one who found ways of meting out justice to all of the characters of the story.