Harold MacGilvray of the Medford Police Patrolmen’s Association said the photo was taken spontaneously during a community festival on Saturday afternoon and was “absolutely not” taken to make a political statement.

The president of a Medford police union said he used “poor judgment” when he posed for a photograph with a person dressed in a Hillary Clinton orange prison-inspired costume that went viral on social media.

Medford MA Police Department Union President Harold MacGilveray on the right, found @HillaryClinton & arrested her. @realDonaldTrump #MAGA pic.twitter.com/2fjap0kFpu

“These were Halloween costumes. It was meant totally as a joke,” MacGilvray said in an email to the Globe. “I apologize if this offended anyone in any way. I never expected this sort of reaction. It was poor judgment on my part.”


MacGilvray and several officers also posed with an individual wearing a Donald Trump mask under the message “Making America great again in West Medford Square!!”

The photos were taken during the Haines Square Annual Fall Festival in West Medford.

The photos was originally posted on the Medford Police Patrolman’s Association’s Facebook page, but have since been removed.

But Twitter erupted soon after their posting.

A Republican state representative in New Hampshire, Al Baldasaro of Rockingham County, posted a photo of MacGillvray and tweeted it to the Clinton campaign.

“Medford MA Police Department Union President Harold MacGilveray on the right, found @HillaryClinton & arrested her,” the tweet stated.

Adam Sennott can be reached at adam.sennott@globe.com.