No one seems quite clear whether the story is originally from the court of Mary Queen of Scots (because there were courtiers named Mary Seton and Beton, but no Mary Hamilton, in her court) or the court of Peter the Great. Robert Masse's biography of Peter the Great identifies a MARIE Hamilton in that court as having been executed, after bearing and killing three children sequentially. He does not suggest that Peter was the father, although sometimes that is said in.
Certainly not in the court of Catherine the Great (Catherine II) who came along a few decades later. Peter's wife was crowned Catherine I when he died. Different person. Professor Child believed the Ballad must have come from Mary Queen of Scots' court, believing it was too well seasoned to have arisen as recently as Peter the Great. But I don't believe there is any record of a Mary Hamilton in Mary Stuart's service.
I think all this proves that ballads are not a good historical source. Folk singers performing on stage may be even less reliable.