This is something I have noticed as a non-native English speaker. When African Americans speak, they usually have a distinct accent that differs from white Americans from the same area. However, when I listen to British people speaking I do not see a vast difference between the accents. How did this historically happen that in Britain the black population did not create a community accent while in the US they did?
Why do African Americans have a distinct accent when African British do not?
Your premise is flawed, at least the end of it is. Stepping away from the "African" label for a moment, and focusing on the last question you posed:
How did this historically happen that in Britain the black population did not create a community accent while in the US they did?
There are a wide variety of British dialects, and some of those dialects have long been recognized as distinct to black British people, speaking with separate accents from their white neighbors.
In 1982, David Sutcliffe wrote Black British English, which explored the topic, whereupon a review of the book published in the Educational Development journal wrote even at that point that the linguistic perspectives offered in the book "are not particularly new".
Perhaps more informative is the academic review of the book published in the Language journal of the Linguistic Society of America, a review written by linguist Frederic G. Cassidy, founder and editor of the Dictionary of American Regional English:
"It is perhaps not generally realized, in the United States, how large the communities of Blacks in British cities are—or the extent to which West Indians who now live in Britain (especially Jamaicans) form communities of their own, following the universal tendency of immigrants to crowd together for fellowship of their own kind and speech...The children, mostly born in Britain, are now forming substantial minorities in the schools, and adopting school English there—but keeping up Caribbean creole at home and in their own groups. In other words, a British Black English (BBE) of West Indian origin exists alongside English, raising problems of school policy and broader ones of general social adjustment."
As Cassidy points out elsewhere in his review, a plurality of black British people, at least at that time, descended from Caribbean immigrant communities, and the creoles and dialects they brought with them were carried over into distinct accents in the U.K., with Jamaican immigrants being the most substantial influence.
This population was not uniform throughout Britain at that time, he says, where less than 1% of the population of Scotland and Wales was non-white. Instead, the black population were concentrated in industrial and metropolitan cities, singling out Nottingham and Birmingham, but especially London.
Since that time, a predominantly black British accent of London has been more thoroughly studied, and is a dialect known to linguists as "Multicultural London English" (MLE). However, since you asked about "African British" specifically, it should be pointed out that "African British" and "black British" are not nearly as synonymous as "black American" and "African American" are.
In the study "Contact, the Feature Pool and the Speech Community: The Emergence of Multicultural London English" by Jenny Cheshire, et. al, published in the Journal of Sociolinguistics in 2011, the authors studied a handful of features and word choices of MLE among different communities living in North London. They found that, among members of the Black Carribbean, Turkish, and Kurdish communities, the use of the studied features of MLE was at about 70% of the population, while among Black Africans, the use was just over 50%.
Anyway, there are black British accents, even if they are not as strongly correlated with the African community as they are with Caribbean communities. In the U.S., "African" is probably a bit of a misnomer on this topic, since the "African American" community is centuries old, and also integrated many people from the Caribbean, and other places, and not just Africa. In the U.K., MLE is sometimes pejoratively referred to as "Jafaican", whereas in the U.S., African-American Vernacular English (AAVE) doesn't have a particular association with the Caribbean.
Further, while these accents were introduced by black immigrant communities, they aren't the sole propriety of black people. There are non-black people in the United States who speak natively in one of the AAVE accents, and, as explained in an article published by the Department of Language and Linguistic Science, University of York, there are non-black people in the U.K. who natively speak in the MLE accent.
Further Reading:
Cheshire, Jenny, et. al. "Language Contact and Language Change in the Multicultural Metropolis", published in Revue Française de Linguistique Appliquée.
Fox, Sue, and Eivind Torgersen. "Language Change and Innovation in London: Multicultural London English", published in Sociolinguistics in England, ed. by Natalie Braber and Sandra Jansen.
Kerswill, Paul. "The Objectification of 'Jafaican': The Discoursal Embedding of Multicultural London English in the British Media", published in Mediatization and Sociolingustic Change, ed. by Jannis Androutsopoulos.
Segovia López, Sara. "Multicultural London English: A Dialect Emerged from Immigration".
See also:
"Who speaks MLE?" web page by the Department of Language and Linguistic Science, University of York.