If the spyware has installed as a system app, a factory reset will not remove it. A factory reset only clears the user data and cache partitions: it does not alter the system partition. In this case, something like Malwarebytes or other app, that looks for behaviors consistent with malware, is advised.