Politicians are supposed to be political. That's kind of the point.
The President, in particular, has a "bully pulpit". Part of his job is to make symbolic statements that encourage people to do the things he wants them to do, to adopt the values he thinks ought to be the country's values.
In this case he is encouraging science while chastising overreactions, especially overreactions which an awful lot of people think are based on bigotry.
Should "pop tart boy" have gotten an invite? If he had been handcuffed, fingerprinted, and had a mug shot taken, he very well might have gotten one. However, perhaps not, because while there was an overreaction to the pop tart incident, it wasn't something that we necessarily want to encourage. We shouldn't care very much if kids chew pop tarts into the shape of a gun and use it as a toy, but we do want kids to wire up electric circuits in novel ways.