It’s not the first time one of the president’s tweets has made light of violence. Last month he retweeted an image of a train running over a cartoon person with a CNN logo over its head. A White House official said at the time that the tweet had been posted inadvertently, and the image was deleted.

In July, Mr. Trump posted a video of him body slamming a man with a CNN logo superimposed over his head.

The post with the golfing GIF on Sunday was just one of several eclectic tweets that Mr. Trump sent, hours before his trip to New York, where he will address global leaders.

In one, he referred to a conversation with President Moon Jae-in of South Korea. “Asked him how Rocket Man is doing,” Mr. Trump wrote. Soon, “Rocket Man,” an apparent allusion to Kim Jong-un, the leader of North Korea, was trending on Twitter.