The best way to answer this question is to understand what an employer can't legally do. From that, we can answer this question. Because there is no law against an employer telling people they can not talk to someone...not directly. Instead, we have to dig deeper to their motivation.
An employer can't legally discriminate based on race, religion, gender, age, disability or recent FMLA use. So, if the reason this employer is making this demand is based on harassment due to one of those factors, it would then be an illegal form of discrimination to make this demand.
An employer can't stop employees from talking about workplace issues, wage and hour issues, safety issues, etc. To do that would be in violation of the National Labor Relations Board regulations, OSHA regulations and Department of Labor regulations. If the employer's motivation is to stop the free flow of information about the workplace and it's issues, then the employer can only restrict the time, place and manner of the conversation (not during work hours, not on the main floor, only in break rooms, etc.), but can't fully restrict speech.
However, if the issue is just one of perceived productivity loss or a recognition that two employees shouldn't be talking with each other during work hours because they don't get along or cause workplace issues, that is not illegal.