Elizabeth initially put Mary under house arrest in 1568 because Mary was suspected of having been involved with the assassination of her second husband, Darnley, in 1567.
We still don’t know if she actually was or not, but it looked bad for her because she married Bothwell, the man who was suspected of having been the main conspirator behind the assassination shortly after, though it’s possible the marriage was not exactly consensual on her part.
Darnley was not a popular man in either England or Scotland (because he was a Catholic and also, had an annoying, arrogant personality) but the suspicion that Mary was involved with his death was why she was forced to abdicate in favor of her son with her half-brother as regent.
Still, it’s important to remember that Mary was kept under house arrest in England for around twenty years before being executed, even though movies like to severely compress the timeline.
Well technically, Elizabeth had legal grounds to imprison Mary from the start. Mary had spent several years claiming the English throne was rightfully hers before she visited England, putting the English coat of arms on her royal insignia and other symbolic yet inflammatory stuff. This means she was essentially a pretender to the throne, who Elizabeth could’ve imprisoned and executed as soon as she was in England. However, Elizabeth didn’t really want to openly go down that route, since it could encourage people to look carefully into Elizabeth’s own claim, which wasn’t very strong in the first place. Killing Mary could also open a potentially dangerous debate about whether or not it was okay to kill monarchs.
So to side step all this, originally, Mary was placed under guard for her own protection. Since she fled to England in danger from her own people, Elizabeth said she wanted Mary placed in protective custody while the matter was cleared up. Over time, the protective custody gradually transitioned into imprisonment as the inquiry into Darnley’s murder revealed a lot of damaging evidence.
However, the inquiry eventually just sort of fizzled out without declaring Mary guilty or innocent. Elizabeth purposefully did this because she didn’t really want the troubles that came with executing or releasing Mary. While Mary was in this legal limbo though, she kept choosing to get involved in plots to depose Elizabeth. This then gave Elizabeth a reason to imprison her regardless of whether or not Mary killed her husband or was a pretender to the English throne. Probably, imprisonment in some random backwoods castle is what Elizabeth wanted for Mary. But eventually, after too many times getting caught trying to murder Elizabeth, Mary had to be executed or Elizabeth would look weak.
More nuance to what others already said:
Mary arrived in England in 1568 looking for sanctuary from her cousin Elizabeth. Mary had been implicated in the murder of her husband, Henry Stewart Lord Darnley (fairly or unfairly, we don’t know for sure but Mary’s actions before and after the murder were very suspicious; it’s clear that she and her councilors wanted him gone).
Darnley was an English-born Catholic with claims to the English throne and Mary and Darnley had an infant son, James. Elizabeth and her councilors had actually somewhat arranged the marriage but Mary and Darnley’s strong Catholic claims to the throne were a growing threat to Elizabeth in England, especially as she was getting older and didn’t have an heir of her body (she turned 35 in 1568, not past childbearing but getting there). Catholic leaders in Europe were sending secret operatives to England with the intention of stirring political and religious dissent and (ideally, in their minds) replacing protestant Elizabeth with a Catholic ruler, thereby returning the country to the Catholic Church. Elizabeth’s government was starting to limit Catholics’ freedom due to the growing political threat – something Elizabeth had been loathe to do having experienced religious persecution in her sister’s reign.
After her husband’s murder, Mary either ran away with or was kidnapped by the guy who was most credibly accused of killing Darnley, Lord Bothwell. They married, but with his boorish, overbearing personality he was reviled by the ruling elite in Scotland. The Scottish lords were tired of Mary and wanted her gone. There was a lot of ugliness (to gloss over a bunch of stuff) and finally Mary abdicated and was imprisoned. She escaped and rode for England to seek sanctuary and an army (from Elizabeth) to help her regain the Scottish throne.
But Elizabeth and her councilors knew they didn’t have the whole story about the Darnley murder and didn’t want to get involved in something so morally fraught by supporting Mary’s claim. And, not inconsequentially, Mary had the best Catholic claim to the English throne and had claimed England as her birthright in the past. Also, there was the growing internal threat to Elizabeth’s throne from English Catholics and Elizabeth’s lack of a son. Many in England would have liked to return to the old religion AND get a male heir and a younger queen (with proven fertility) in the bargain. Win win win. So Mary turning up penniless in England was a big problem for the government.
It doesn’t appear that Elizabeth intended to lock Mary up for such a long time when Mary first arrived, but they really didn’t know what to do with her. Elizabeth made an overt show of treating Mary badly to keep her distance from a suspected husband-murderer (sending her rags instead of the noblewoman’s clothes Mary had asked for), but also wrote Mary letters trying to establish a relationship. During her imprisonment, Mary started colluding with Catholic dissidents and Elizabeth’s spy network knew it.
Elizabeth’s government wasn’t prepared to 1) march an army to a now-Protestant Scotland to re-take Mary’s crown, 2) release Mary to the continent where she could raise an invasion against Scotland and potentially (the bigger prize) England, or 3) let her live a free life in England as a guest of her cousin Elizabeth. The only safe choice was to keep her in custody.
As Mary’s imprisonment dragged on, the less and less likely it was that England would destabilize Scotland’s Protestant government (and potentially England’s) by setting her free. James made noises about the injustices to his mother, but he was raised strongly Protestant, he and his guardians *really* didn’t want her back in Scotland. So Mary plotted to try to get her freedom by overthrowing Elizabeth (imagine if she had succeeded!) and finally the English government found her too big of a threat and executed her. Elizabeth, famously, made a big show of being against the execution, and probably was personally, but she knew the political calculus as well as anyone and Mary was an unmitigateable threat. Mary and Elizabeth never met.
Of course, Mary’s execution was one of the impetuses for the attempted invasion of England by the Catholic Spanish Armada . . . but that’s a story for another evening.
Elizabeth I’s father started the Church of England partially to divorce his current wife and marry Elizabeth’s mother. The Catholic Church considered Elizabeth illegitimate and Mary was close in line, which made her a threat when Mary Queen of Scots showed up in England. I don’t know that Elizabeth necessarily had a legal reason that allowed her to do it.
I’m not entirely sure if it’s ever been proven whether Mary Queen of Scots was really plotting against Elizabeth I or not. I would say it’s definitely possible but I can’t currently find any sources to confirm it either way.
As to not killing her for a long time, I believe Elizabeth I may have felt a woman who was a queen in her own right executing another woman who was a queen in her own right would have set a bad precedent. Executing another monarch sets a bad precedent when you yourself are a monarch, especially when many people wanted Elizabeth’s throne and could use the excuse of her illegitimacy.
Many people believed that Mary had more of a claim to the throne than Elizabeth, being a “more” legitimate heir and catholic. The country was pretty divided at the time, as Henry VIII just introduced the Church of England during his reign to legally remarry multiple times and people were politically divided being protestantism and Catholicism. The Protestant claim to the throne was weak after Henry VIII because his only son was sickly and died young and named one successor, Lady Jane Grey, who was thrown out of power very fast by the Catholic daughter of Henry VIII Queen Mary I, aka Bloody Mary. She persecuted Protestants in England during her brief reign and tried to re-establish Catholicism. Elizabeth I was the only heir after Mary I’s death, leading to a Protestant country again. Elizabeth wanted a Protestant country, and Mary Queen of Scots was a Catholic threat and a hope to her catholic people of a Catholic ruled country once again
Mary Queen of Scots has a tragic life. She was forced to abdicate her rights to her Scottish throne to her young son after being accused of plotting to murder her second husband, who was trying to take over her throne. Its unclear if she was in on the plot to kill her second husband, but third husband was accused of murdering the second. Not a good look for Mary. This pissed of the Scots and she gave up her throne willingly and was sent to live in exile for pretty much the rest of her life. She escaped imprisonment in Scotland to England, where Elizabeth I took care of her but she was pretty much her prisoner too. This is where and when she was accused of plotting to overthrow Elizabeth, and was excuted by Elizabeth order because after Elizabeth was protecting Mary, Mary did her dirty. But this was Mary’s only was to freedom, and to gain her born right as queen again on the English throne.
These women were similar ages, both queens and also family. They exchanged letters throughout their lives but never met. They had so much in common, but they just could not have a friendship because being royalty used to be a blood bath.
Edit: made booboo with all the husbands