Why would Africa install coal? It's way more expensive than solar, and coal makes them dependent on imports. Once installed, solar is independent energy.
The same reason African nations build railways and ports they strictly don't need - China and various world banks are continuing what European countries used to do, cheap "upfront" capital loans for expensive infrastructure projects that benefit resource extractors and other that prey on small nations.
Your rational long term argument has little sway when key decision makers are bribed and offered a chance to retire to a mansion elsewhere on the planet.
As of today the majority of China's coal activity in Africa is directly related to China's mining activity in Africa to provide power for ectraction, processing and townships.
That mining activity is 'small' in the sense that Chinese mining companies represent ~ 8 percent of Africa’s total output in the sector and are concentrated in just five countries: Guinea, Zambia, South Africa, Zimbabwe, and the Democratic Republic of the Congo (DRC).
Resource extraction from those regions back to China is currently approx. $13 billion US (for resources that would likely cost 5x that cost if sourced from Canada or Australia)
China is not alone and by no means the greatest extractor; Anglo-American alone accounts for more than double that 8% share.