Why did He bring darkness on them? Because there were among the Israelites of that generation evil people who did not wish to leave, and they died out during the three days of darkness so that the Egyptians not see their demise...R. Ya'akov Kamenetsky pointed out that just about all the Jews at that time were sinners, even idolaters. So why did only some of the die during the plague of darkness? I think a careful reading of Rashi tells us the answer: "evil people who did not wish to leave"
Yes, there were plenty of wicked people who committed the most terrible sins. But sins didn't prevent Jews from leaving Egypt and being brought to Israel. It was those who refused to leave, who for some reason did not want to leave Egypt or thought for some theological reason that they shouldn't leave, who deserved to die in this plague.