Peter Capaldi portrayed another Doctor Who character before being cast as the Twelfth Doctor, and there's a very good reason for that. Both the classic and modern incarnations of Doctor Who have reused certain actors for multiple roles. Colin Baker, for example, played a Time Lord called Commander Maxil in 1983 before debuting as the Doctor's next regeneration just over a year later, and this tradition has continued into the modern Doctor Who era. Before starring as Martha Jones, Freema Agyeman played an employee of Torchwood and Karen Gillan appeared as a Soothsayer before accompanying the Eleventh Doctor as Amy Pond. Unlike the classic series, however, some of these coincidences were addressed on-screen, as Martha was revealed to have a relative who worked for Torchwood.
Perhaps the most famous example of the dual casting phenomenon in Doctor Who is with Twelfth Doctor actor, Peter Capaldi. Appearing in "The Fires of Pompeii" - the same episode Karen Gillan debuted in, incidentally - Capaldi took the role of Lobus Caecilius, an aspiring politician and family man who encountered David Tennant's Tenth Doctor and Catherine Tate's Donna Noble. Due to the Doctor's (rather flexible) law about not interfering in key events, the duo are forced to abandon Caecilius to the doom of Pompeii's infamous eruption but, at Donna's request, the Time Lord decides he can save one family without impacting history too heavily.
Five years later, Capaldi was cast as the Twelfth Doctor after being considered the heavy favorite for some time, and fans wondered whether the Caecilius connection would be addressed, as with Martha Jones, or ignored à la Colin Baker. That question was answered in the Twelfth Doctor's very first full episode, "Deep Breath." Spying his new face while passing a mirror, the Doctor recognizes the man staring back at him and begins to question why his new regeneration had taken on the visage of someone from a previous adventure.
The Doctor realizes the meaning behind his resemblance to Caecilius in the following season's "The Girl Who Died," claiming that the likeness was a deliberate reminder to always try and save lives, even if doing so appears to go against certain rules or laws.
While this may seem like a convenient, tacked-on piece of Time Lord mythology, there is actually precedent for Time Lords borrowing a person's appearance when they regenerate. During Tom Baker's tenure in the TARDIS, the Doctor and Romana (played by Mary Tamm) encountered Lalla Ward's Princess Astra. The following season, Ward replaced Tamm as Romana's next regeneration, explaining to the Doctor that she simply liked Astra's appearance.
Peter Capaldi actually played a third character in the Doctor Who canon: John Frobisher in Torchwood. Frobisher was a civil servant of the British government tasked with handling an alien race called the 456, but he suffers a far darker fate than Caecilius. Responsible for several reprehensible acts, Frobisher is forced by the Prime Minister to hand over his own children to the 456 as a sacrifice. With no other option, Frobisher kills himself and his family to spare them that horror. The Doctor had no direct contact with Frobisher and the character's visual likeness to Capaldi is never addressed, although it's possible that the Doctor may have later found out about the 456 invasion at a later date. If this were the case, perhaps the Twelfth Doctor's face is not only a reminder to always save people, but also that, sometimes, the villains need rescuing too.
Doctor Who season 12 premieres in 2020 on BBC and BBC America.