Thank you for using JustAnswer.
I'm sorry to hear about your situation. Yes, it would be legal, although their laying you off might be "retaliation" for your harassment claim (especially if they say they were laying you off due to cost-cutting / economic pressures). The act of hiring someone else prior to laying you off is not illegal. The question is whether them laying you off in the first place would be legal.
New York is an "at will" employment state. At-will employment means that without a contract, you have no contractual or other right to employment with the company. The company is entitled to fire you for any reason: a good reason, a poor reason, or no reason at all--as long as the company does not fire you for an illegal reason (race, gender, age, religion, etc...). But it extends beyond firing, to hiring, promotions, demotions, wage cuts and raises, disciplinary actions, and even scheduling. Unless you can show that this was done in violation of a contract, union agreement, or a clear violation of an unambiguous and binding clause against the employer, or that it was done because of some minority status (age, race, gender, religion, disability) that you have, then they do have this discretion.
Again, the fact that they hired someone else prior to laying you off wouldn't be illegal. But if your harassment claim was based on race, age, religion, gender, or disability, or sexual harassment, etc... then you could have a case for retaliation, and you should file a complaint with the EEOC: https://www.eeoc.gov/employees/howtofile.cfm
Hope that clears things up a bit. If you have any other questions, please let me know. If not, and you have not yet, please rate my answer AND press the "submit" button, if applicable.
Please note that I don't get any credit for the time and effort that I spent on this answer unless and until you rate it positively (3 or more stars). Look for the stars on your screen (★★★★★). You may need to scroll left/right/up/down to see these stars, but note that the rating is what closes out this question, so it is necessary that you do so.
Thank you, ***** ***** luck to you!