If Force users to log in was enabled and Alternate login URL was set to the site's home page then this would cause a loop between these two pages. You can check this in the database:
SELECT name, value FROM mdl_config
WHERE name IN ('forcelogin', 'alternateloginurl');
+-------------------+------------------+
| name | value |
+-------------------+------------------+
| alternateloginurl | https://site.com |
| forcelogin | 1 |
+-------------------+------------------+
If this is the case you can override these settings by adding the following to config.php:
$CFG->alternateloginurl = '';
$CFG->forcelogin = 0;
The other cause of this error is when a reverse proxy is being used but normally the loop is to the same URL only. If this was the case, $CFG->reverseproxy = true would need adding to config.php.