In addition to the back-alley scum and villainy of the The Mandalorian, also contends with Imperial Stormtroopers — despite the fact that the Empire was defeated years earlier. The Star Wars franchise is filled with characters, starships, and weapons that have become iconic in modern pop culture, including stormtroopers, the quintessential sci-fi foot soldiers. Variants have been created in the prequel and sequel trilogies relating to the Republic and the First Order respectively, but stormtroopers remain most closely associated with the original trilogy's Galactic Empire. So why do they appear in The Mandalorian?
The Galactic Empire was created when the Darth Sidious, under his public name Sheev Palpatine, manipulated the emergency powers granted to him during the Clone Wars to restructure the government of the Galactic Republic. Simultaneously, the Sith Lord and his new apprentice Darth Vader nearly exterminated the Jedi Order, thereby removing what would otherwise have been a significant threat to their totalitarian power.
The Mandalorian takes place after the final triumph of the Rebel Alliance. However, while the Battle of Endor and the destruction of the second Death Star did mortally wound the Empire, the Galactic Civil war did not officially end until their surrender more than a year later, following the definitive Battle of Jakku. Given how closely The Mandalorian follows the original trilogy chronologically, it makes sense that there would be Remnant Stormtroopers still caught up in the long, drawn out process of defeat, even after the Imperial Instruments of Surrender were signed. And the Empire occupied large swaths of known space, making it all the more likely that some holdout troopers would be able to escape with their equipment to inconspicuous planets.
Although The Mandalorian is set in the run-up to the time period of the sequel trilogy, these stormtroopers shouldn't be confused for the First Order Stormtroopers seen in those movies. As established in voluntary recruitment of the Empire. And while some of the Empire's final rank and file would be partially responsible for founding the First Order later on, many Remnant Stormtroopers resorted to a life of mercenary transience, relying on their training and the long history of menace that their armor provided. This may or may not involve loyalty to the fallen Empire, as Gideon, who the troopers in the series ultimately serve, was almost certainly offering greater incentives to his followers than the simple hope of serving a (presumably) dead Emperor.
Star Wars is easily the most famous example of the space opera genre, and the films in the Skywalker Saga comport themselves with all of the pulpy melodrama implied therein, with the war between good and evil waged on a galactic scale and defined by a series of climactic battles. But in keeping with its more grounded, Western-influenced tone, The Mandalorian chooses instead to focus on people caught in the grey, liminal times when the hard lines between eras in history become blurred, and this includes paradoxical Remnant Stormtroopers, set adrift, for better or worse, in the absence of the grand authority that they were meant to represent.