In short, yes, Tolkien intended for racism to be a consistent theme in his writing, mainly in order to display the folly of racism.
One relevant quote suggests that, at least in some cases, races in Middle-earth are analogous to races in our world:
The dwarves of course are quite obviously - wouldn't you say that in many ways they remind you of the Jews? Their words are Semitic obviously, constructed to be Semitic.
― J.R.R. Tolkien
What negative stereotypes apply to real world Jews and Tolkien's Dwarves? One need look no further than Elrond's comment at the council:
Who will you look to when we've gone? The Dwarves? They toil away in caverns, seeking riches. They care nothing for the troubles of others.
So Dwarves care only about material wealth - a common slur leveled at Jews by antisemites for centuries.
Although this question isn't about whether Tolkien himself was racist, I feel obliged to point out that Tolkien was not an anti-semite. During the Nazi regime, when his German publisher wrote to ask him if he was Aryan, he was furious, as three letters quoted on the Tolkien Gateway page on racism in Tolkien's works demonstrate:
"I must say that the enclosed letter from Rutten & Loening is a bit stiff. Do I suffer this impertinence because of the possession of a German name, or do their lunatic laws require a certificate of arisch [i.e., Aryan] origin from all persons of all countries? ... Personally I should be inclined to refuse to give any Bestätigung (although it happens that I can), and let a German translation go hang. In any case I should object strongly to any such declaration appearing in print. I do not regard the (probable) absence of all Jewish blood as necessarily honourable; and I have many Jewish friends, and should regret giving any colour to the notion that I subscribed to the wholly pernicious and unscientific race-doctrine."
― Letter 29 — Tolkien's German publishers had asked whether he was of Aryan origin
"Thank you for your letter... I regret that I am not clear as to what you intend by arisch. I am not of Aryan extraction: that is Indo-Iranian; as far as I am aware noone (sic) of my ancestors spoke Hindustani, Persian, Gypsy, or any related dialects. But if I am to understand that you are enquiring whether I am of Jewish origin, I can only reply that I regret that I appear to have no ancestors of that gifted people."
― Letter 30 (Tolkien's unsent response to his German publishers; a more neutral version was ultimately sent)
"There was a solemn article in the local paper seriously advocating systematic exterminating of the entire German nation as the only proper course after military victory: because, if you please, they are rattlesnakes, and don't know the difference between good and evil! (What of the writer?) The Germans have just as much right to declare the Poles and Jews exterminable vermin, subhuman, as we have to select the Germans: in other words, no right, whatever they have done."
― J.R.R. Tolkien — September 23, 1944
Another, more obvious example of races in Middle-earth as analogies for real world races is the inhabitants of the Shire - it is well known that the Shire is Tolkien's idealized vision of England before WWI, and the hobbits are his idealized version of the English people.
There is a page on Tolkien Gateway titled "Racism in Tolkien's Works" (also linked above), and it contains this passage:
Tolkien portrays racism within the "heroic" races as unabashedly negative. Elves and Dwarves distrust each other. Some Elves hunted the Petty-dwarves as animals, as did the Rohirrim to the Woses. The friendship between Legolas and Gimli is portrayed as unusual but commendable, and several scenes illustrate them learning to understand and respect each other's cultural differences. When Gimli takes a strand of Galadriel's hair, he is described as having "look[ed] into the heart of an enemy and saw there love and understanding."
It is notable that there is apparently racism within the ranks of Orcs as the Uruk-hai held themselves as superior to the common Orcs, whom they called snaga (slave).
The point-of-view characters of the book -- the hobbits -- are themselves of a race that is frequently described as being overlooked, under-estimated, and lightly regarded by the other races of Middle-earth, yet they often demonstrate far greater courage and nobility than the races who denigrate them. They are not without prejudice, however, and Gandalf is shown reprimanding Frodo for his comments on Barliman Butterbur.
The Númenóreans of Gondor fell to infighting because of a supposed need for racial purity, especially concerning the ancestry of their king (the Kin-strife), and grew weaker as a result. In this affair, the villain was the pure-blooded Númenórean Castamir while the hero was the half-Númenórean Eldacar.
It also says
Of the orcs, the Uruk-Hai are described as "black" and a smaller orc, a tracker, is described as "black-skinned". All orcs are often described as "slant-eyed" and the Uruk-Hai at least refer to the Rohirrim as 'white skins.' In one of his letters, Tolkien described Orcs as "...squat, broad, flat-nosed, sallow-skinned, with wide mouths and slant eyes; in fact degraded and repulsive versions of the (to Europeans) least lovely Mongol-types."(Letter 210)
However, it continues, and suggests that this obvious racism might be forgivable, at least in part:
While Tolkien's statement comparing Orcs to the "Mongol-types" is undoubtedly insensitive given today's standards, he does put a disclaimer, "(to Europeans,)" before "least lovely", at least recognizing Western cultural bias and also points out that they were "degraded and repulsive versions" of "Mongol-types", not actual "Mongol-types". It is worth noting that some Orcs use crooked or bent swords (Tolkien also uses the term scimitar, which are historically associated with the Middle-East).
The "Middle-earth & J.R.R. Tolkien Blog" addresses this issue at length, and seems to summarize the answer very well:
Q: Is It True There is Racism in The Lord of the Rings?
ANSWER: Yes, it is true there is racism in The Lord of the Rings. However, many people who ask this question may really mean to ask, “Is The Lord of the Rings a racist work of fiction?” Although some people claim that is the case they are mistaken for J.R.R. Tolkien embedded numerous examples of the folly of racism in The Lord of the Rings. In other words, it would be difficult for any other modern work of fiction to be as anti-racist as The Lord of the Rings.
While I haven't found a statement from Tolkien that clearly and directly says he intended to address racism in his books, these passages from three of his letters give some indication of how strongly he felt about such matters; the third goes a bit further, and suggests that he did indeed intend to infuse his work with his own contempt for bigotry:
"I have the hatred of apartheid in my bones; and most of all I detest the segregation or separation of Language and Literature. I do not care which of them you think White."
― From a valedictory address to the University of Oxford in 1959
"As for what you say or hint of ‘local’ conditions: I knew of them. I don't think they have much changed (even for the worse). I used to hear them discussed by my mother; and have ever since taken a special interest in that part of the world. The treatment of colour nearly always horrifies anyone going out from Britain, & not only in South Africa. Unfort[unately], not many retain that generous sentiment for long."
― Letter 61 — Written to Christopher Tolkien who was stationed in South Africa during World War II
"Anyway, I have in this War a burning private grudge—which would probably make me a better soldier at 49 than I was at 22: against that ruddy little ignoramus Adolf Hitler (for the odd thing about demonic inspiration and impetus is that it in no way enhances the purely intellectual stature: it chiefly affects the mere will). Ruining, perverting, misapplying, and making for ever accursed, that noble northern spirit, a supreme contribution to Europe, which I have ever loved, and tried to present in its true light."
― Letter 45
Considering how much attention to detail Tolkien invested in his writing, and how strong were his feelings on racism, it is all but impossible to imagine that the frequent, incredibly numerous, and consistently negative allusions to racism in his books are anything less than completely deliberate and intentional. He definitely meant to expose the evils of prejudice.