Yes, iPhone spy apps do work when two-factor authentication is turned on. You will need to catch the authentication code that is sent to the target iPhone after the user's iCloud credentials have been entered.