File lib/db/upgrade.php line 3494
https://github.com/moodle/moodle/blob/MOODLE_37_STABLE/lib/db/upgrade.php#L3494$context = context_user::instance($userevidence->userid);
This function tries to find an existing user, because it cannot find the washed down user about the deleted user in the table context. Attempt to update fails. The second update is successful.