Margolyes, 82, who has starred in Blackadder, Babe and the Harry Potter films, will appear as the voice behind Meep, the creature adapted from The Star Beast comic strip.
She said: “I’m relieved I got to work on Doctor Who before I died. With sci-fi you never know.
“Thank you for making an old woman very happy.”
Doctor Who will return for three special episodes this November, featuring David Tennant as the 14th doctor and Catherine Tate playing his sidekick Donna Noble, to coincide with the celebrations marking six decades of the show.
The first of the three specials will be titled The Star Beast, while the second is Wild Blue Yonder and the third is The Giggle.
Sex Education star Ncuti Gatwa will take over as the Time Lord after the three specials, alongside Coronation Street actress Millie Gibson, who is playing the Doctor’s companion Ruby Sunday.
Gatwa’s first episode as the 15th doctor will air over the festive period, with Gibson, 19, becoming the youngest companion in the show’s history.
The series will also include RuPaul’s Drag Race winner Jinkx Monsoon, Heartstopper actress Yasmin Finney and American actor Neil Patrick Harris.
The latest revamp of the series sees It’s A Sin writer Russell T Davies return as showrunner, the man behind the 2005 revival of the long-running BBC show, succeeding Chris Chibnall who introduced Jodie Whittaker as the 13th Doctor.
Doctor Who will air on the BBC in the UK and Ireland, while streaming platform Disney+ will show episodes to audiences elsewhere.