What is the purpose of increased penalties under various specific
circumstances?
It has to do with both offender's mental state at the time of committing the crime, and the increased vulnerability to which society is subjected by that criminal conduct.
In a context of traffic violations, texting while driving reflects the driver's reckless disregard of the safety of others. It is reckless because the consensus that texting while driving is dangerous has been continuously reminded for several years now. Thus, a person who insists to text while driving indicates a clear disavowal of even the most basic safety rules.
Likewise, texting absorbs the driver's attention, eyesight, and hands to perform tasks that demand considerable precision: Reading messages, locating little keys in the keypad, and keeping both hands away from the wheel. These factors severely impair a driver's ability to react to events happening outside the vehicle and/or to correct the driver's inadvertent mistakes (such as zigzagging). That misconduct renders everyone else vulnerable to significantly greater damage than if the driver refrained from texting. Thus, deeming texting an aggravating factor is an attempt to outweigh the control that handheld devices exert on certain type of drivers.
By the same token, a rationale can be developed for the scenario of drug dealing nearby schools. It also touches on both aspects: criminal's mental state, and people's increased vulnerability.
is it just a way for politicians to claim they are "tough on crime"?
Yes, there might also be a factor of that sort, even if the politician's or officer's words are inconsistent with his or her acts.
Consider Michigan "Justices" such as Joan Larsen (currently in the Sixth Circuit Court of Appeals) and David Viviano. They like to market themselves with slogans such as "protecting the children" and "fight corruption on the bench", but both (and indeed every "Justice" in the Michigan Supreme Court except Bernstein) largely sided with judge Lisa Gorcyca after she threatened, extorted, and jailed for 17 days three innocent kids under the pretext that they refused to have lunch with their father.
That is an example of openly posing as "tough on crime" while declining to truly sanction a judge who deliberately did the opposite of protecting these three children.