Even if it is illegal for them to use it, the courts have ruled that law enforcement can use illegal tools during investigations, and then lie about it in court without compromising their case.
The legal term for this is “parallel construction”.
Even if the courts threw out cases that were built this way, it is hard to detect, and most cases don’t go to court.
Even if prosecutors behaved ethically, and didn’t pursue such cases, there are well-documented problems with organized crime infiltrating police departments, and then being difficult to bring to justice (e.g. LA’s deputy gangs have had control of a chunk of the LAPD for over 50 years).
The best solution is to ban the collection of the data in the first place.