Earnest's comments followed a tweet by President Barack Obama offering support for the teen, a student in the Dallas suburb of Irving.
Ahmed was invited to participate in an astronomy night the White House is organizing next month with leading scientists.
Earnest says the invitation was offered as a way for Ahmed to "nurture that intellectual curiosity."
The boy was placed in handcuffs, and his family says he was suspended from school. Police announced Wednesday that they would not seek any charges against him.
The family is holding a news conference at 4 p.m. Wednesday.