No, it is not illegal. An employer may post, advertise, recruit, etc. at any time, including before an employee is terminated, the same way a landlord may advertise for prospective new tenants before the old tenant's lease is up or they have left. It may be insensitive and, at least in some cases, unprofessional to do this, but it is legal.