The NBA is unique in this because their players union lobbied successfully for guaranteed contracts, so you get your money no matter what. Whereas the NFL, which is its own weird set of really odd mandingo fighting issues, does not have such a contract structure so, if you're a running back and you blow out your knee in game 1 of your first season, too fucking bad.
It's racist because in just about any other profession (other than the NFL because of literal concerns for the physical safety of the human body, maybe) you could conceivably become an earning professional straight out of high school if you are skilled enough. Why do they insist on making people go to one year of college? To learn life skills? No. It is because if these dudes could go get paid right outta high school, then they would. And then people would lose interest in collegiate basketball, which by and large makes its millions off of the labor of an unpaid, largely black workforce. If the "good" players are going straight to the NBA, the product of the NCAA suffers.
Ergo...the rule.