Kurosawa drew inspiration for Yojimbo from Dashiell Hammett's pulp detective novels, Red Harvest in particular. He restaged/adapted the story to feudal Japan (much as he did with Shakespeare in Throne of Blood and Ran). This type of tale can be set anywhere.