Can someone please explain how accents work?

As a Black man with a "white voice," I'm acutely aware of accents and their ability to foster instantaneous affinity with members of a specific tribe. In certain parts of the Black community, choosing to talk "properly" can create more significant social rifts than actually insulting someone in an accent they approve of. Consequently, most Black Americans choose to "code switch" (or augment their accent and colloquialisms to establish camaraderie) with either white and Black folks. But the bigger question is, why do accents vary so wildly?

I grew up around Black people, yet I don't "talk Black" – barring my generous use of "urban" colloquialisms. If we develop accents as a subconscious form of social bonding, why did my brain decide to mimic Wayne Brady's voice as opposed to Gucci Mane's? Surely, I would've had an easier time in my immediate environment with the latter than with the former.

Well, after a lifetime of mild curiosity around the subject, I decided to exorcise my ignorance. In the video embedded above, the YouTube channel Thoughty 2 talks about how accents work and how they develop in the brain.