Yes, so long as they do not overreach
Please note this is a common law answer, it may not be applicable in civil law jurisdictions like most of the EU.
Like non-compete clauses and non-disclosure agreements, non-solicitation agreements can be unenforceable restraints of trade if they are not reasonable.
Reasonable in this context means they are narrowly focused to protect legitimate business interests. A business does not have a “legitimate business interest” in preventing their competitors from poaching their employees in general - a business does not have a right to keep their employees. Therefore, analysis of the agreement must focus specifically on how an ex-employee can “unfairly” solicit compared to an unrelated corporate headhunter.
In practice, this makes them hard to enforce but they are not prohibited.