Hiring a private investigator to follow someone is not illegal as long as the private investigator is not doing any illegal activities during the following of the person they've been hired to follow.
However if you hire a private investigator to do something illegal when following someone then that would be illegal but most legit private investigators are knowledgeable in what to do to stay legal when hired to follow someone.
They would not risk their private investigator job by doing something illegal.