Hiring a private investigator is perfectly legal and won't get you into trouble as long as you hire a professional private investigator who obeys the laws.
Most private investigators will obey the laws and know what they can and can't do so that you and them won't get into trouble.
However if the person spots the private investigator following them then they might call the cops and report someone stalking them which may or may not get the private investigator into trouble.
But a lot of people do hire private investigators and nobody usually gets into trouble for it.
Just make sure the private investigator is a reputable private investigator and has good reviews and knows what they're doing.
Don't always go for the cheapest private investigator but make sure you find a good reliable and trustworthy private investigator.