This is because the Space Marines, the Imperium and Warhammer40k as a whole are concepts that are heavily inspired by Human history, dating from the earliest written records to the twentieth century. The intellectual freedom of the author, in this case GW, allows them to utilize these historic examples, place them in a futuristic setting, hand-pick which black-and-white aspects they want to use, and leave out the undefined grey areas. The result is a sci-fi universe that encompasses something for everyone. No matter what period of human history you find appealing, there will be an equivalent in this setting. In your case, it is the Space Marines, whose historic equivalents are the medieval knights, more specifically the crusaders, and the chivalric ideal image of a knight. The organization that best mirrors them is that of the Knights Templar, as all historical aspects, from faith to their role as an elite fighting force, to their subsequent betrayal by power figures found it's way into the image of the Space Marine, although the Warhammer version is much brighter in some cases. There are lore fragments from WH40K rulebooks that speak of Ecclesiarchal cardinals finding chapters wanting, and ordering them to embark on crusades into the eye of terror, which is pretty comparable to the fate of the Knights Templar in France. In the case of the Space Marines however, we see that the story goes on to tell of Space Marines surviving those crusades to return and slay these religious authority figures for their heretical betrayal. On the opposing side of the spectrum, we find the Chaos Space Marines, WH40k's rendition of the black knight, the antithesis of knightly virtues. For me, it is the Imperial Guard, which invokes mankind's collective memory of all theatres of world war 1 and world war 2. Every single army in WH40k can be compared to a historical equivalent, and every society shares a resemblance to one as well. The Imperium in particular manages to capture pre-rennaisance medieval Europe and the Roman empire very clearly, but we can also find parallels to other eras that are less clear cut, like the collapse of human society prior to the dark age of technology caused by warp storms to the 1200 BC simultaneous collapse of Mycenean Greece, the Egyptian New Era realm, the Hittite Empire and the Assyrian Empire. tl;dr: Anyone that loves History, or badass dudes in power armour, laser rifles, explosions, flying tanks, jetpacks and chainsaws can not help but love Warhammer 40k.
When it comes to the Tau, one can see fairly strong ties to Oriental cultures, more specifically Japan. A few indications for that connection is firstly the use of mecha suits, their voice acting in Dawn of War: Dark Crusade, but there is one other connection, that is slightly less clear. When one looks at real life history, it becomes fairly obvious that no one really expected the Japanese empire to become a threat to the overseas possessions of western nations. Some understood this better than others, but in any case the magnitude of the threat was misunderstood. One reason for this is ofcourse the fact that the western powers considered themselves slightly superior, although this notion had already started declining, but another reason is that Japan industrialized relatively late, and did so practically unnoticed. In 1853 an American naval squadron under the command of Matthew Perry forced Japan to open it's ports to foreign merchants. An indirect consequence was the fall of the shogunate in 1868. In 1871, Samurai officials were sent to Western europe to learn about western politics, economy and technology(One of the Samurai class' last contributions to Japanese history, in fact), and by 1900 Japan was an industrial nation, although it still depended on western imports to keep it's economy running. These political, economic and technological changes went unnoticed by most of the world, and as a result, Japan was able to perform very impressive military feats during the second world war, until the turning point at the Battle of Midway, which cost their navy too many carriers. The Tau are similar to this because they too went from a bunch of (in the eyes of the Adeptus Mechanicus Explorers) primitive savages living on a single planet to a highly advanced empire(The lore states that a warp storm enveloped their planet, and that they emerged as gundam users, pretty much). In fact, their battlefield technology surpasses the Imperium of man, but their crucial weakness is that the Tau Empire does not have access to interstellar flight(A major logistics problem during an interstellar war) and does not have access to the same kind of reserves that the Imperium can bring to bear. The rulebook simply offers us the explanation that the Imperium is too invested in fending off hive fleets and the current Black Crusade to give much of a fuck about the Tau. If the timeline of WH40k ever progresses(Which it probably won't) it will be interesting to see whether the Tyranids or the Imperium gets to them first.
The Tyranids have a shorter explanation. They have no historical counterpart in human history, and their main inspiration were the creatures from the movie Aliens. A marvelous addition nonetheless.
Orks are very strongly based on the stereotypical image of "The barbarian" that we have inherited from the Greeks and Romans. Basically a bunch of foreign tribes that they can not comprehend the motivations and methods of, who tend to form large hordes. The notable difference is that historical barbarian hordes were more of an armed refugee collumn. For instance, most of the hostile tribes that invaded the Western Roman Empire did so because their other option was being massacred by the Huns. The Orks actually stay closer to the Barbarian stereotype created by the Romans, that they are simply wild savages looking for a fight. If one compares these two images, one starts to see a relation:
http://static1.1.sqspcdn.com/static/f/170895/5315238/1263072461923/bad_posture_2.gif?token=GKb1yy6HGQEuqNYPQFrQ9X/acm0= http://img03.deviantart.net/5e6a/i/2013/289/c/2/warhammer_40k__ork_boyz_by_thomaswievegg-d6qp7ry.jpg Notice the similarities between the slumped posture? Where the Space Marines are an incarnation of the stereotype of knightly orders, the Orks are an incarnation of the stereotypical barbarian whose life was centered around fighting and looting. Again, Games Workshop focuses mainly on the black and white aspects, and leaves out the grey ones.
The Necrons are the WH40k incarnation of the Tomb Kings from WH Fantasy, which drew it's inspiration from ancient Egypt.
The Eldar are technically an incarnation of the High Elves from WH Fantasy, however, their history and culture would indicate that their inspiration came from a combination of what we know about the Hittites, Assyrians, Akkadians and Babylonians. Technically, the Eldar were the first race to have an Empire in WH40k, which puts them in the same category as the Akkadians on our planet. The Eldar were also one of the first races to fight the Necrons. If we assume the Necrons to be Egyptians, then one could draw a parallel to the Hittites. Their culture and religion also has a few resemblances to Assyria and Babylon. In any case, I would not draw such a strong parallel between them as I would with the Imperium and Western Europe in the dark ages, as the connections are not as clear-cut. in any case, I would search for what inspired the WH40k Eldar in pre 1200 BC mesopotamia.
The Dark Eldar are a tad harder to explain, but we know that raids by folks known as the "Sea Peoples" caused the complete destruction of many cities in the middle-east, such as the City of Ugarit, which was literally destroyed by a raid whilst they were baking clay tablets to warn neighbouring cities and nations of an incoming invasion from the sea. Many historians also point to these "Sea peoples" as a possible cause for the collapse of Mycenean Greece, which caused a dark age in Greece between 1200bc-900bc until the classical period began. Games Workshop probably did not base the Dark Eldar on these guys, but there are a few striking similarities. So yes, if I do in-depth research into a WH40k faction I can definately draw a parallel to some long-gone kingdom or empire, but it is most clearly visible when you look at the Tau and the Imperium.
The Imperium itself is a bit of an odd one, because it appears to have elements of many different eras in Roman history. The Emperor-veneration cult definately stems from the Roman Imperial era, but then you have the Ecclesiarchy and Inquisition, which would represent the Papacy and the IRL inquisition, which didn't form until after the Western Roman Empire fell. The Space Marines we've discussed beforehand, and the only historical equivalents for the Imperial guard are seen during WW1 and WW2. I specifically place them in that period because they are mass armies led by a General with a Staff. Not the walking instrument, but an actual general staff. This is something we do not see in a Space Marine chapter, for instance, where each force is led by a force commander, and you have a chapter master at the head. In terms of organization, the Imperial guard as a fighting force has a much stronger resemblance to the armies that took to the field in 1918. I say 1918 specifically because Artillery did not play a major role in the earliest battles, and Tanks didn't really make an appearance until the second half of the war. By 1918 however, Imperial Germany can see all the characteristics in the opposing Western Allies that we know from the IG in WH40k. Mass infantry formations, concentrated usage of tanks, overwhelming use of artillery and the prospect of unlimited reinforcements(in the form of the Americans), complete control of the sea(space in case of WH40k, courtesy of the Imperial Navy) to prevent supplies or friendly forces from arriving and the prospect of suffering a defeat through attrition. I add World War 2 to the list as well, because while World War 1 comes close to what we are used to from the Imperial Guard, it is the Red Army as seen between 1943 and 1945 that truly comes the closest to the IG. Ofcourse the main beauty of the Imperial Guard is that there is literally a regiment or planet to represent every single military force in History from the US troops in Vietnam(Catachan) down to the Huns(Attilan Rough Riders).