Yes it is legal, otherwise they may be slitting their own throats. I bet the contract was drawn up by the recruiting company.
Please only call me if your case is in California as I am only licensed here and laws of other states may vary. I approach trials and issues from a legal and common sense approach, This is how the majority of judges I have appeared before in 40 years also make decisions. I do not intend by my advice to enter an attorney client relationship and in most cases advise to obtain legal representation. Sometimes if you can not afford it a consultation or limited scope representation is available. As an experienced attorney I can tell you, judges can be impatient, hate emotional arguments and over exagerations or lies. A brief outline of the problems and desired solutions is always best and I often in limited scope representations advise clients on how to proceed at time of hearing or trial and my fees are considerably less when I do not appear in court as it takes much less of my time.
Put a clause in the contract that says exactly what you want it too. "The ABC company will not recruit for employment elsewhere any current employee of the principal, and in regards to this agreement ABC company is acting as a fiduciary of your company." See an attorney contracts prepared by others could by laced with objectionable, vague, ooppressive or other clauses. An hour of pre-counseling often saves a year of itigation.
Every thing that I am saying here is my opinion and it is not based on any particular case. My response is just unsupported general information. If it helps you to resolve an issue that's great but do not rely on it as legal advice because it is not based on the facts in your case and it is not based on any specific legal research. Answering this question creates no relationship between the writer and reader of the writing. I am not your attorney now, nor have I been on the past.
There is nothing illegal about your company insisting that a recruiting firm it is paying to assist the company not at the same time recruit the company's employees to work for another employer. This does not prevent anyone at your company from working anywhere they want to. It simply means that they may not be able to use the services of this particular recruiting firm to help them get there. Technically, you or anyone else at the company should still be able to approach the recruiting firm; in other words, it's okay for the company to tell the recruiting firm that they can't solicit the company's employees, but the employees should still be able to approach the recruiter. Nevertheless, even in this case, it is likely that the recruiting firm will not want to jeopardize its relationship with the company by talking to an employee who approaches them. Their decision is also entirely legal.