I can imagine several instances where it would be reasonable and legally defendable, I.e. not illegal in that the judge must acquit.
For instance, my company makes the fiber spitter that can make N95 mask filter material, and you frantically ordered 100 of them for next week. We can build them, but we need your operational supervisors to take a 4-month course on operating the machines, because it isn't simple and you can destroy the machines if you do not know what you are doing. So in lieu of that, I require you to take 2 of my engineers.
For many years, it was SOP for IBM to allow and encourage their large customers to hire their engineers away. This was one strategy IBM used both to keep their "no layoffs" record perfect, and of course the people they nudged out the door were marginal performers or frustrated with the IBM culture. So this created a very happy ending, cementing brand loyalty with both the engineer and the customer.
As a nonprofit grant issuer, I get to have a say in who exactly you hire for that executive director position I am funding.
So this kind of "backroom deal" is not unusual at all.
However, in general, the employer has an EEOC problem. (Equal Employment Opportunity Commission). If a qualified applicant feels that they were passed up on account of their gender, race, religion and certain other protected classes, then the employer needs to show that was not the case. Nepotism complicates that, although nepotism alone is not a violation of EEO law. Just like you can't refuse housing to a qualified black person, but you can refuse housing to a qualified black person if you moved your cousin in instead. Here enters the "Where's the victim?" question: now you have an aggrieved party coming at you, and you must at least grind through the case.