Probably because the black president on the show was portrayed as a strong leader and Americans thought they could get life to imitate art by electing one of their own. Of course there were plenty of movies in the ensuing years that featured a black president before we had one. But anyway...
Morgan Freeman had already played a black President in the movies years before that.
Nobody voted for Barack 0bama because of 24. In fact, I doubt many of the people who watch 24 would even have been part of his constituency.