In Bereshit (21:17) Rashi tells us that the Angels wanted G-d to kill Yishmael, but G-d said that He wouldn't judge him according to his future deeds, but rather according to his present state:
In the place where he is. [I.e.,] he is judged according to his present deeds and not according to what he will do in the future. For the angels were declaiming against [him] and saying, "Master of the universe, for one whose descendants will eventually kill your children with thirst You will provide for him a well?" And He responds to them, "But, what is he now, righteous or wicked?" They respond to Him: "He is righteous." [Whereupon] He responds to them: "It is according to his present deeds that I judge him."
The Talmud (Rosh Hashana 16B) uses this story to teach us that a person is only judged according to his present deeds (at the time he is being judged).
But in (Sanhedrin 101B), Rashi quotes a Midrash that tells us as follows:
Moshe told G-d, "You have done bad to this nation, because now if they don't have bricks [the Egyptians] put the children of the Jews in the building [in place of the bricks]."
G-d responded to Moshe, "They are destroying thorns [i.e. people of no value]. I know that if they would live they would be wicked (another version: completely wicked). If you want, you can test me and remove one of the children."
Moshe saved a child and it was Micha.
(Micha is said by some to have been the one to create the Golden Calf, and is said by others to be the same Micha who made the "Pesel Micha" at the end of the Book of Judges - see here)
Here we have a child who is completely blameless, yet G-d wants to kill him because of his future sins. Why does this differ from Yishmael?
Many commentaries ask what the difference between Yishmael and the Ben Sorer U'Moreh is: In Devarim (21:18,22), Rashi tells us that a Ben Sorer U'Moreh is killed because if he wasn't killed, he would ultimately become a degenerate:
Verse 18: ...The wayward, rebellious son is executed in consideration of his ignoble end. The Torah penetrates to the logical conclusion of his thought--- ultimately, he will squander his father's fortune, attempt to apply himself to his studies and fail, station himself near an intersection and plunder his fellow creatures; the Torah declares: Let him die in innocence rather than die laden with guilt.
Verse 22: If a man is guilty of a capital offense. The proximity of the chapters teaches that if his mother and father take pity on him, he will ultimately develop into a degenerate, commit transgressions, and be sentenced to death by the courts.
The commentaries give many answers why a Ben Sorer U'Moreh is killed if he hasn't sinned yet. Most of these answers focus on explaining that the Ben Sorer U'Moreh is indeed being judged according to his present actions.
For example, the Mizrachi answers (see here) that the Ben Sorer U'Moreh has already started sinning, so he is not entirely blameless. The Gur Aryeh answers that we are killing him because Torah says that a son who fulfills the criteria of a Ben Sorer U'Moreh should be killed. While it's true that Torah has a reason, namely because of what he will become in the future, Beit Din only kills him because he is now halachically in the category of a Ben Sorer U'Moreh (i.e. because of his present deeds), not because of what he will become.
All these answers make the question about the children used as bricks even stronger. If we only judge based on present actions, why kill the children because of their future actions?
Even the answer given by the Devek Tov, differentiating between Yishmael, whose descendants would sin, and the Ben Sorer U'Moreh, who is himself a sinner, seems to only answer why Yishael wasn't killed. The Devek Tov himself brings a different answer to explain why the Ben Sorer U'Moreh should be killed. He says that the Earthly Bet Din is judging him based on his future actions, but the Heavenly Court only judges based on present actions.
If so, the question remains. Why did the Heavenly Court (G-d) decree to kill the children in Egypt, they presently were not wicked?