I don't have a problem with Trump signing MAGA hats for troops. I wouldn't have had a problem with Obama signing his book for troops.
Where I might have a problem is with the provenance of the hats. Is the Baghdad PX selling them? That's a no-no. Did they come in "care" packages from loved ones? That's fine, if misguided. Did the Trump advance team provide them? That's bad and illegal.