In addition to what the parent says about PR, there are some actual good reasons:
1. Some companies are starting to understand and believe that having a diverse team is a competitive advantage when it comes to designing and marketing products intended for a diverse audience.
2. Some companies are starting to believe that it's just the right thing to do to try to increase diversity in their ranks, to attempt to combat systemic sexism and racism that historically has kept certain groups on the sidelines for some roles.
Whether you agree with these things or not, companies are increasingly believing in them, and that's at least a part of why they go far beyond what the law requires when it comes to anti-discrimination. I find it unlikely that a company would lose a court case for not pushing to hire more diverse candidates, or not having implicit-bias training, or not removing terms like master/slave or whitelist/blacklist from their internal lexicon. It does not seem like companies are doing this because they are afraid of running afoul of the law.