Consider a sole proprietor. It's detrimental to society if she refuses to hire black people. It causes social tension, an underutilisation of labour and is just plain racist.
Now consider an investor-owned company. We don't want managers hiring their friends and family over qualified candidates. It wastes capital, promotes inequality and impairs labour utilisation. (It also messes with education incentives). All that makes raising money harder for everyone which, in turn, makes the economy less effective.
TL; DR Employers being racist hurts other people. Hence, we regulate it.
It's also illegal in the US.
Couldn't the market take care of racism? Nowadays if a company is dumb enough to make blatantly racist things, the social media makes sure that people know this, and not racist people will think twice when dealing with that particular company. However, if racism is hidden behind internal processes, e.g. they don't openly reject minorities, just set the bar higher for them when hiring, it can be really hard to unveil the misconduct.
Expecting the market to solve these problems is naive, it just won't happen except in a few high profile cases.