Beacuse these national teams auction off their friendlies to other countries. So whatever organisation/country is hosting the match will demand that certain star players play as part of the deal.
Last season there was a controversy over Messi not playing vs Morocco in a friendly, and there had also been reports about components of the deal that made Morocco promise they wouldn't tackle him. There was also controversy with Ronaldo staying on the bench in South Korea during Juve's preseason tour. These hosts buy the rights to the friendlies and promote the big name players to sell tickets. If that weren't the case, then there's now way in hell Messi or Aguero would've even been called up this month, since they both normally sit these international breaks out.