And as a bonus question, why is is so popular in some strains of pan-Africanism and among some Black American movements?
This question I think has two strands: one discussing how Swahili came to be the predominant trade and intermediary language of East Africa, and more modern attempts to officialise it as the premier language of the region. Both are strongly linked, but the latter owes a lot more to modern-day African nationalism than the former.
Swahili is a member of the Bantu language family, the parent group of the vast majority of spoken languages native to Sub-Saharan Africa. Specifically, it descends from the Sabaki language which predominated on the East African coastlines of Kenya. It gained prominence as a trade language, particularly after the growth of East Africa's trading city states under the Kilwa Sultanate. These cities traded extensively with the Arab world, Persia, and India throughout the Middle Ages, growing extremely wealthy and building colossal towns up and down what we now call the Swahili Coast. Aside from ivory, gold, and some agricultural goods, the primary trade of these cities was slaves, which were eagerly bought up by Arab traders.
Swahili has some strong characteristics that lends itself to being an intermediary language; it has simple grammar and morphology, can readily accommodate loanwords, and (unlike many Bantu languages) has no tones. This meant Arab traders could quickly pick up the language to communicate with African merchants, and said Africans could easily communicate with their colleagues from different tribes with different first-languages. This also has lent Swahili to having a huge amount of foreign loanwords, primarily from Arabic, including its very name ultimately coming from the Arabic word 'sāħil', meaning coast. Indeed, after a time the Arabic script was adopted as a (woefully inappropriate) means of writing the language down, which gave it a prestige far exceeding the other, exclusively-spoken languages of the Swahili Coast.
Already, the strong trading relationship and economic strength of Swahili centres such as Kilwa and Stone Town had bolstered Swahili's position as a lingua franca, but it was particularly in the latter half of the second millennium that the language began to spread further inland. Due to greatly increasing demand for slaves, as well as increasingly brutal actions by Arab and African slavers, raiding parties would leave the coasts to capture and enslave Africans as far inland as modern-day Eastern Congo, Rwanda, and even Zambia. The most famous example of these slavers was Tippu Tip, who supplied much of the world with slaves during the 19th Century. These raids, in addition to abducting millions of innocent men, women, and children across East and Central Africa, also brought with them the Swahili language, which again took the role of a trading lingua franca. By the time the Europeans arrived and colonized the region, while their languages retained a prestigious position as the language of education and culture, Swahili remained an important intermediary language for administrative purposes, and oftentimes areas would remain under the control of Swahili-speaking feudal lords who merely paid vague homage to their colonial overlords.
That explains how Swahili became so widespread, but to understand its position as an "official" language, and a vehicle for pan-Africanism, one must look to post-colonial nationalism in East Africa, and how it was expressed. In the aftermath of European rule, many countries in Africa sought to craft a new national identity separate from that of their colonial masters and centred on a sense of "Africanness". Linguistics played a huge role in this, with cities such as Leopoldville being renamed Kinshasa, or countries such as the Gold Coast taking the name Ghana to herald an ancient and powerful African empire. In East Africa, which was overwhelmingly a British possession, there was a desire among many to diminish the presence of English as the language of education and culture, and instead teach an African language. This was most present in Tanzania, with their first President and leading pan-Africanist, Julius Nyerere, enthusiastically promoting Swahili as the national language. He felt that Swahili's position as a well-understood language of trade, not closely associated with any of Tanzania's myriad ethnic groups, as well as being authentically 'African', made it the ideal fit for his model state. He was particularly concerned with creating a strong national identity that transcended tribal and religious boundaries, which was especially important with the Christian mainland and Muslim coast and Isle of Zanzibar; Swahili as a unifying language, as well as being easy to learn for Bantu speakers, cut through all of the hang-ups of cultural disunity that might have come from another language, and was sufficiently African to serve as a clean break from British colonial rule. As Tanzania has become an ever important cultural and economic power in East Africa, the influence of Swahili, even on states such as Kenya which had generally leaned more toward English in the past, has continued to grow ever since.
In short, Swahili became a lingua franca due to its suitability as a trading language for merchants on Africa's East Coast, and was further spread widely across the east and centre of the continent due to slavery and further economic expansion, and has since been sustained as a common cultural language of East Africa due to the work of pan-Africanist politicians, educators, and cultural leaders.