Commentary
This question has several aspects, which must be understood:
The Reward for Good Deeds
The reward for good deeds goes to the one who performs these deeds with the intention of seeking Allah’s pleasure and hopes for a reward in return. If a person has no desire for a reward at all, or does not care about it, then when he does not receive a reward, what is there to complain about? Therefore, the reward will be given only to the one who hopes for a reward from his Lord.
The Difference in the Intention of the Deed
The standard of a good deed is that it be done in accordance with Allah’s command and that the intention also be Allah’s pleasure. For example, if a person speaks the truth, but only because he regards it as a business principle or because it brings him personal benefit, then this deed will not be counted as good. The intention behind the deed is the standard of its acceptance.
Disbelief and Good Deeds
Disbelief is like poison for good deeds. For example, if someone cooks excellent food but mixes poison into it, that food will be harmful, not beneficial. In the same way, disbelief renders good deeds worthless.
Summary
Even if an atheist does a good deed, those deeds become useless because of his disbelief, since deeds have no real value without intention and faith.