What was a sleepy Republican nomination contest for Virginia lieutenant governor took a bizarre turn this week after a mailer sent out by former delegate Timothy D. Hugo showed Del. Glenn R. Davis Jr. wearing a rainbow-striped shirt, highlighting several causes Hugo argued were not Republican — including protecting members of the LGBTQ community from discrimination.

On Wednesday, an anonymous cellphone text sent to delegates in the party’s May 8 convention used the same photograph of Davis (Virginia Beach) and accused him of being “a gay Democrat.” The text also called Hugo “the only conservative running for Lt Governor.”

Hugo’s campaign manager, Dustin Rhodes, defended Hugo’s authorized mailer, which landed in mailboxes this week, as a portrayal of Davis’s “liberal voting record” and said arguments about the content were an attempt to distract convention delegates.

But Hugo said the anonymous text message, which he characterized as “ridiculous and offensive,” did not come from his campaign or any of his associates.

In a statement, Hugo said he vowed to learn who was behind the message. In Virginia, a campaign ad must include a statement indicating who paid for it. It was not immediately clear Thursday whether the Virginia Department of Elections was investigating.

“We intend to track those responsible and hold them accountable,” Hugo said in his statement. Rhodes said the campaign plans to turn over whatever information it finds about the anonymous text to state officials.

The text focused on Davis’s support for repealing the state’s now-defunct constitutional ban on same-sex marriage, which has been legal in the state since 2014. “Help Glenn come out of the closet by not ranking him on May 8th,” the cellphone message read. “Tim Hugo is the only conservative running for Lt Governor.”

Davis and Hugo are the two best-financed candidates in a field of six GOP contenders for the lieutenant governor’s seat.

Davis (Virginia Beach) said the message “exceeds the bar of defamation of character.” But, he said, the tactic nonetheless shows that an anti-LGBTQ message can still sway voters in some conservative, more religious parts of Virginia.

“It’s probably a small minority,” said Davis, who has been married to his wife, Chelle, for 16 years.

Other Republicans condemned the anonymous text, calling it an example of a divisive style of politics that has hurt the state GOP during elections as Virginia has become increasingly blue.

Republican Aliscia Andrews, who last year tried to unseat Rep. Jennifer Wexton (D-Va.), said she was disgusted by it. Andrews, a convention delegate, said she was sent the text message Wednesday. She had seen comments on social media from some of the Republican Party’s 53,000 delegates who said they also received the text.

“We can do better than this,” Andrews said. “In such a divided time in our country, we have a real opportunity to treat people like human beings, and rhetoric like this does the exact opposite.”

The issue of LGBTQ rights has been a subject of debate within the Virginia Republican Party for several years, contributing to former congressman Denver Riggleman’s failure last year to win his party’s nomination for a second term after he presided over a same-sex wedding.

The issue also surfaced this year in the Republican nomination race for governor.

In February, conservative businessman Pete Snyder tweeted that he was “humbled” and “blessed” to receive an endorsement from E.W. Jackson, the party’s 2013 nominee for lieutenant governor and a Chesapeake minister known for calling the LGBTQ community “very sick people.”

Riggleman condemned Snyder’s acceptance of the endorsement, tweeting, “The #GOP has no future with this leadership.”

Snyder’s spokeswoman, Lenze Morris, defended the endorsement, saying the candidate “doesn’t agree with everything anyone says.” Asked about the criticism, Jackson said in an email to The Post: “I am a Bible believing Christian. Aside from that I refer you to scripture.”

One of Snyder’s consultants is Diana Shores, who helped lead the effort to oust Riggleman in last year’s convention.

On Wednesday, she praised Hugo’s official mailed flier.

“Kudos to Tim Hugo,” Shores tweeted. “Equality under the law, yes. Pandering to the sexuality club? No thanks. Not sorry.”