I'd treat this as a potential security incident rather than an ordinary redirect problem.
Unexpected redirects can be caused by malicious JavaScript, modified WordPress files, compromised plugins, injected database content or unauthorized changes to your website configuration.
The fact that it doesn't happen consistently doesn't mean your website is safe. Some malware is designed to redirect only certain visitors or devices.
First, take a backup of the current website and database for investigation. Keep in mind that the backup may contain malicious code, so don't restore it blindly.
Then I'd recommend:
- Run a security scan using a reputable malware scanner.
- Review recently modified website files.
- Check WordPress administrator accounts for unfamiliar users.
- Inspect
.htaccess and unexpected redirect rules.
- Review active plugins and themes.
- Change WordPress, cPanel, database and FTP passwords from a clean device.
Also, contact your hosting provider and ask them to check server-level malware indicators.
Simply removing the redirect code may not fix the problem if the original vulnerability is still present.