First of all, a disclaimer that this is a highly sensitive topic - especially because of the current events that have swept all parts of the planet where american (pop) culture is somewhat influential. Personally, I regard this as the long overdue incentive to look at exactly what you are referring to, the - from modern day perspective outrageous, although such a statement is ahistoric - "racist" remarks that you can undeniably find in a lot of Marx's as well as Engels' works (including personal writings such as letters one of which you linked but also published work). For a very long time this has been a bit of a blind spot when it comes to Marxism and/or the study of Marx himself as a figure but the fact that at the moment a lot of people point their fingers at these racist quotes from Marx as a reaction to the removal of slaver-holder statues underlines the importance and relevance of contextualising but not excusing the historical person that Marx was.
As I mentioned, we can find quite a few "racist" remarks that were used by Marx, not just about Ferdinand Lassalle in his letters to Engels in which the racist slurs were often coupled with deeply anti-semetic choices of words - the relation of Marx and Lassalle, the latter being one of the main initiators of an organised socialist movement in Germany, deserves its own post but it suffices to say that despite earlier friendship formed during the revolution of 1848 that subsequently force Marx into exile they had later developped clashing opinions on a lot of political-theoretical matters. You can also often find similarly racially charged language when Marx talked about (or even directly to) his son-in-law, the at times over-looked Paul Lafargue (mostly known for his work titled "The Right To Be Lazy") who was born in Cuba in 1842 as the son of a "creole" mother; the same holds true for Engels, as the following example of a letter of his to Marx's second daughter Laura (the wife of Lafargue) shows:
"My dear Laura, My congratulations to Paul le candidat du Jardin des Plantes—et des animaux. Being, in his quality as a nigger, a degree nearer to the rest of the animal kingdom than the rest of us, he is undoubtedly the most appropriate representative of that district. Let us hope the animaux will have the best of it in this struggle against the bêtes." (Marx/Engels Collected Works. Vol. 48. Letters 1887-90. [Engels to Laura Lafargue in Paris. London, 26 April 1887]. pp. 52-54).
Having in mind these obscenly-worded passages and considering the number of times similar phrases were used by Marx and Engels it becomes virtually impossible to argue that they didn't mean or take them in a serious way and were merely conforming to socio-linguistics standards of their respective time. It might very well be true that mesaured against the vast majoriy of his contemporaries Marx was not "remarkably racist" but looking at Marx's systematic criticism of the existing social conditions of the working class this argument feels very weak - for Marx, black people were not a constituent part of said working class whose conceptualisation was inherently eurocentric. At the same time, Marx and Engels were thus not "above" the concept of race but instead regarded it an important influence on the (in their theory, natural) evolution of the economic and social conditions. Carlos Moore once wrote about this: "Marx and Engels clearly believed that race was one of the factors acting upon the social evolution of human societies."
That said, Marx also famously congratulated Abraham Lincoln opening his letter to the newly re-elected president on behalf of the International Workingmen's Association in November 1864 as follows: "We congratulate the American people upon your re-election by a large majority. If resistance to the Slave Power was the reserved watchword of your first election, the triumphant war cry of your re-election is Death to Slavery." So what we have, is a very ambivalent picture of Marx who on one hand held deeply racist views "endowing 'races' with inferior and superior qualities all the time" which can also be seen in his theoretical work while also welcoming certain waves emancipation on the other hand but in a way that was still undeniably racist as it made the disctinction between what he regarded as less-capable "african" and as he called it "yankicised" black people.
Marx was no anti-racist, something that is now deeply ingrained in left-wing politics. To quote Moore once again: "Marx's and Engels' political judgements, theoretical conclusions, and philosophical analyses on the most wide-ranging questions were naturally conditioned by their being Westerners, not Africans or Asians; Whites, not Blacks or Yellows; free men of the nineteenth century, not chattel slaves or colonial subjects." What that means for the historicity of Marx and his theories depends on your intepretation. But it without doubt requires a deep self-reflection within every group that claims tradition to Marx's ideas.
This wasn't a very direct answer to your questions but I hope it shows that looking at the historical issue of Marx and racism is very necessary as well as interesting.
Sources:
Marx/Engels Collected Works. Vol. 48. Letters 1887-90.
Marx, Karl: Address of the International Working Men's Association to Abraham Lincoln, President of the United States of America. Presented to U.S. Ambassador Charles Francis Adams January 28, 1865.
Hund, Wulf D.: Der ‚jüdische Nigger‘ Lassalle. Marginalie zu einem Brief von Karl Marx. 2018.
Moore, Carlos. "WERE MARX AND ENGELS WHITE RACISTS?: THE PROLET-ARYAN OUTLOOK OF MARXISM." Berkeley Journal of Sociology 19 (1974): 125-56. Accessed June 26, 2020. www.jstor.org/stable/41035216.
The racial slurs are directed towards Ferdinand Lassalle (of Jewish descend), one of the founders of the German social democratic movement of the 19th century. The communists at the time were skeptical of the legitimacy of German "Lassalleanism." Both camps had their fair share of political conflict and because of this, Lassalle ended in Marx' crosshairs more often than not. I can't go deeper into this, because I don't know much about the personal relationship between him and Lassalle. However I'll attempt to give some broader meaning to Marx' and Engel's views on race and ethnicity, which hopefully will satisfy OP's inquiry somewhat.
The use of racial components can be found scattered all around Marx's and Engel's writing and are disturbing and troubling. Initially it could be explained that for 19th-century-standards these remarks were common, but it does not explain how they could be so racist yet hold the view that the relationship between class and commodity production came first when analyzing history. However I don't think Marx' and Engel's views on hereditary racial characters are incompatible with a Marxist materialist worldview.
I believe both of them regarded racial-ethnic qualities as something which is closely linked with the underlying economic basis of society. Marx saw racial-ethnic characters not as eternal human qualities, but as products of economic and environmental factors, which in turn are in constant development and motion. Marx and Engels made the human character very dependent and adaptable to the environment, so it could be argued that it is precisely the environment which plays the primary role in creating hereditary racial communities.
It could be said that both writers held the notion that humans living and working under the same social relations of production, under the same natural conditions for longer periods of time, would tend to grow certain shared ingrained racial profiles (either negative or positive). Consecutively these racial profiles would change throughout history.
They both held very nasty ideas on black people, but both men supported abolitionism and in 1864 Marx urged Lincoln, 'to lead his country through the matchless struggle for the rescue of an enchained race and the reconstruction of a social world.' Before he wrote to Lincoln, in a letter to Engels in 1853 he states that 'present negro generation in America represents an indigenous product, more or less turned into Yankees, English speaking etc. and therefore becomes capable of emancipation.' He also claimed that the Chinese people were awakening form their 'hereditary stupidity' in the wake of the Opium War and the Taiping Rebellion.
In short I think that both writers believed that humans and nation-states are a product of their history, not of innate biology.
Edit: added quote from letter to Engels, 1853.