if an unhandled error happens then it will check the database to see if an upgrade is needed
based on the code version vs database version it detects if an upgrade scripts need to be run and if so it redirects to setup
if it cannot detect the current version it assumes it is a new installation and it needs to run setup so it redirects there
It does not happen if the site is taken offline on purpose or if the site is closed
If this is happening frequently for unintended reasons you should probably check with your host about the reliability of the connection to the database and review the mojoPortal log for errors under Administration > System Log