In general, it seems like they got there from East Africa but except this I haven't seen anything that touches on how. What were the Trade routes, which states/tribes were they bought from and which peoples made up their Number.
The presence of this particular slave population was the direct result of Abbasid efforts to reclaim agricultural land in the marshy regions of southeastern Iraq in the estuaries of the Tigris and Euphrates rivers. By the 7th century CE, much of these lands had been abandoned by the inhabitants in favor of the emerging urban centers such as Basra, Baghdad, and Wasit. The local inhabitants had largely abandoned their ancestral farming plots to pursue better opportunities in the cities, leaving behind the very tough conditions of life in the marshes. In their absence, the land returned to a "wild" state and was covered in a layer of natron. Mosquitos and therefore disease were a constant problem as well.
Enterprising elites with Caliphate support, especially from Basra, began to take an interest in reclaiming these lands for cultivation. This required an intensive effort of "cleaning" the land to expose the topsoil by removing the natron, recreating or redirecting the many canals, etc. For this purpose, a large number of slaves were purchased or forcibly removed from the "Zanj" region of eastern Africa. They were Bantu speakers for the most part, from the Swahili coast. There is not a lot of scholarship available online about the actual transport of these groups to southern Iraq, so I am unable to talk about specifics in that regard.
Once there, the slaves endured very harsh conditions and generally poor treatment. They were generally lodged in crowded camps and given very few supplies for survival (food, clothing, proper shelter, etc). This type of slavery is said to be unusual for the Islamic world of the timeāthe standard line is that the typical context of slavery was domestic and urban, with none of the ruthless agricultural slave populations familiar from the Roman world (e.g.). This effort in the marshes was therefore unusual. Due no doubt to the horrific conditions, there were a series of uprisings and troubles, culminating ultimately in the great uprising of 869 CE.
See:
Popovic, Alexandre. The Revolt of the African Slaves in Iraq in the 3rd/9th Century (Markus Wiener, 1999)
Talhami, Ghada Hashem. "The Zanj Rebellion Reconsidered." The International Journal of African Historical Studies, Vol. 10, No. 3 (1977), pp.443-461.
this article, but I do not have access.
this master's thesis from Univ Louisville might have some good info, though keep in mind this will be the work of a junior scholar.