The vast majority of stalkerware requires the hacker to physically get hold of your phone and either install an app or make configuration changes to your device. Therefore, it is important to protect your device with a strong passcode that only you know.
Some stalkerware can also steal data from your iCloud account without needing to install an app onto your phone. Enabling two-factor authentication for your account will protect you from this type of stalkerware.