Sir James, who was a prominent supporter of the Union before the 2014 independence referendum, said he and Mrs Weir, who were born in England to Scottish parents, were considered “the wrong kind of Scots”.
He wrote: “A patriot angrily tweeted that I must ‘go back to England’ because I am ‘not a Scottish citizen’.
“Some others were annoyed by the title of my anthem ‘Who Shall Separate Us?’ implying that this contained a dastardly hidden Unionist code designed to tamper with the Scottish brain.Read:‘Carnage’ at Royal Liverpool Hospital as people treated in ambulances ‘queuing for hours’
“They seemed unaware that St Paul’s Letter to the Romans contained a lack of advice on Scottish constitutional reforms.”
Sir James, former composer-conductor of the BBC Philharmonic Orchestra, said it had been a “great honour” to write the anthem in tribute to the late Queen.
He wrote the piece ten years ago, but its existence was a secret until the order of service was published on Sunday night.
“I was told that this passage from Romans 8 was important to the queen because it goes to the heart of her relationship with Jesus,” he said.
“Her Christian faith was an inspiration to millions, perhaps billions, around the world, and her ability to convey it with dedication and pastoral insight in her Christmas messages and on other occasions was the focus of significance in her life and example.Read:Roller-skater causes panic after almost crashing into King Charles’s car
“I have seldom thought so deeply about a text, both during its drafting and in the years that followed.”
Donald Cameron, constitutional spokesman for the Scottish Tories, said it is “a regrettable reflection of the SNP’s obsession with independence” that “zealous nationalists” were looking at virtually everything “through the prism of the constitution”.
He added: “The fact that a new national anthem, written for Her Majesty’s funeral, caused a backlash for the supposedly pro-union message, would be comical if it weren’t so sad.
“As one of the country’s foremost composers, James MacMillan deserves much better than this.”
The SNP has been contacted for comment.