A few reasons
#1 - To sell more jerseys. He was sick of getting beat by people like LeBron since everyone already owned his #8. Yes, he's that much of an egomaniac. Believe it.
#2 - To wear #24 so he could be "one more" than Jordan/LeBron
#3 - To try to be the player who gets two different numbers retired by one team. Jordan tried this when he switched to #45, but promptly went back to #23.
#4 - To symbolize his evolution during the second half of his career from a selfish, egomaniac, whiney superstar who wears #8 to a selfish, egomaniac, whiney superstar who wears #24.