The casting was annoying to me way back when it was first announced. This was, in part, because it was a harbinger of things to come. It told us that everything was on the table and that the story we got in the film would be related to the setting we knew only in name, i.e. the names of the characters (people, places, and things). I was never worried about the acting ability of Idris (or any of the actors released). To me it was all about the writing, and the casting choices they made all but ensured that we were going to get a reheated Hollywood slice of stale pizza.
But let's step away from the specific film and address the convention of changing ethnicity and/or gender in stories. It clearly can be done. The only question then is whether or not it should be done. By in large, characters (historical or fictional) have a designated ethnicity and gender. Those details are, in fact, almost always revealed early (if not immediately). A very common mistake in writing is to go too long in not describing a character in enough detail. When you describe them after too much time has passed the reader is often jarred from the story as they must now reconcile the image they created in their heads (filling in the blanks the writer didn't) with what is now given. Thus, most writers give details early and use "character defining" details. In short, they use description to further reveal character and make their antagonist unique. This is why translating a beloved book to the screen can be challenging. No actor selected is going to fit the ideal image millions of different people have imagined, but said actor MUST (at least in my opinion) have or pay lip service to those character defining details. People who have never read the book do not have this hurdle, naturally, but one must assume that the die hard fans of the book will be the first ones to see it (particularly when the studio does almost ZERO promotion). It is their word of mouth which is going to be heard most loudly. Thus, if you disorient them too much by not matching their expectations, the word of mouth is not going to be good.
So continuing on the "why" aspect of changes in the ethnicity and gender of characters, what are the reasons it sometimes happens?
1. Shock value. It is very commonly done for shock value, whether as a protest or simply publicity.
2. Name recognition. It is sometimes done because Hollywood has a hot property (or a Studio already as a contract they can leverage).
3. And rarely it is done because the Actor/Actress in question is deemed to be the best for the role.
That last one is almost always the STATED reason, when in reality it is almost some combination of the first two. Going back to the film in question, Idris is a great actor. That doesn't mean he was the right one for this role. Hollywood is full of amazing talents. They are dime a dozen. Idris was selected because he is a hot property. Was that a good reason? As it turned out, no. Name recognition did little for the film. But then again, I'm one of those people who thinks the writing has to be good or the film will still be garbage regardless of who is in it. A hot property can only add to a film if there is something to add to in the first place.