lib/authlib.php defines both prelogin_hook() and prelogout_hook(). It seems there is a bug in login/logout.php as it runs prelogin_hook() instead of prelogout_hook() for each of the enabled authentication plugins.
In addition to that, the hooks are run even if the user chooses not to logout, because the hooks are run before the notice_yesno() call to confirm the logout. So we need to move the hook calls after the logout confirmation check.
The attached patch solves both issues.