Hiring a private investigator is not illegal but the private investigator you hire must only do the spying and investigations legally and not do illegal things when doing the private investigations.
If you hire a private investigator to do some illegal things then yes that would be illegal and could get you both into trouble.
Most legit private investigators will do what they can legally to carry out the private investigations so as long as you hire a reputable private investigator then everything should go smoothly.