It's basically because of trading. Muslim merchants would come to trading places around Africa and talk to the people about their religion. Through cultural diffusion, other people started adopting the religion that then just became a family religion which people kept.