Maintenance mode and user session
This is intended behavior, if user does not have "access site in maintenance mode" permission, then user is logged out.

For Drupal 7 take look on user_menu_site_status_alter

For Drupal 8 take look on Drupal\user\EventSubscriber\MaintenanceModeSubscriber