First, let’s be clear that “aks” is not limited to African Americans. While it is part of African American Vernacular English, that is not the only context in which it can be heard. “Aks” can be found in some places in the American South (which isn’t surprising since AAVE is largely derived from, and has a lot of overlap with, other dialects of the rural South), as well as certain parts of New York City (especially Staten Island). It can also be found in the Caribbean and in South Africa (where it is common among people of Indian descent). So while it is both regional and cultural, it is also said by black people, white people, and even Asian people.
“Aks” is also a historically common pronunciation. Neither “ask” nor “aks” existed in Old English, but the word from which “ask” is derived did. Linguists have decided that the standard form of that word was “ascian” (pronounced “as-kee-an”). But the alternative form “acsian” (pronounced “ak-see-an”) actually appears more frequently than the standard form (most notably in Beowulf, which is arguably the most important piece of Old English literature we have). “Ascian” is only considered “standard” because we’re pretty sure it was derived from the proto-Germanic word “aiskon” (which is a reconstruction, not a word found in any surviving writings) and because we know it eventually became “ask.”
That said, it wasn’t exactly a straight line from “ascian” to “ask. Both “ask” and “aks”/“axe” appear in Middle English, and it is again “aks” or “axe” that is found in some the most important surviving works of that era (such as Chaucer’s Canterbury Tales). The alternative form also appears (as “axe”) in the first complete Modern English translation of the Bible (the Coverdale Bible, published in 1535). In short, “aks” has been a part of the English language for a long time and appears in all three major forms of the language (Old English, Middle English, and Modern English).
So why does this happen? The answer is metathesis (“mə-TA-thə-səs”)—the transposition of two sounds (usually adjacent consonants) within a word. Metathesis is so common that you probably do it without even thinking about it (for example, if you’ve ever pronounced “comfortable” as “comf-ter-ble” instead of “com-for-ta-ble”). We naturally tend towards pronunciations that are easier. In practice, this means moving our mouths less, which in turn means not making our tongues or our jaws move back and forth more than necessary. Instead, we tend to prefer pronunciations that allow us to move less and more smoothly.
Words that require us to make sounds in the front of our mouth, then the back, then the front again (or other combinations that skip around) inevitably undergo change over time and are often preceded by dialects containing that change. Words that allow us to move smoothly from sounds made in the back of the mouth to sounds made in the front of the mouth or vice versa, on the other hand, are more likely to be stable over time (barring other sound changes). The standard pronunciation of “ask” requires us to transition from a starting position to a middle position to an ending position. By contrast, “aks” requires only a single transition from the starting position to the ending position. This makes “ask” a prime candidate for metathesis. This doesn’t mean that we’ll all be saying “aks” in a thousand years. But if we are, it won’t be that big of a surprise.