You could use WP Cron to fire wp_logout() and make it more reliable by following instructions here https://developer.wordpress.org/plugins/cron/hooking-wp-cron-into-the-system-task-scheduler/
Below is code for a plugin that would log everyone out, every day at midnight. Note if you wanted to schedule a one-time-only, single event, use wp_schedule_single_event instead of wp_schedule_event https://codex.wordpress.org/Function_Reference/wp_schedule_single_event
// hook function myplugin_cron_hook() to the action myplugin_cron_hook.
add_action( 'myplugin_cron_hook', 'myplugin_cron_function' );
/**
* Create hook and schedule cron job on plugin activation.
* Schedule recurring cron event.
* hourly
* twicedaily
* daily
*/
function myplugin_activate() {
$timestamp = strtotime( '24:00:00' ); // 12:00 AM.
// check to make sure it's not already scheduled.
if ( ! wp_next_scheduled( 'myplugin_cron_hook' ) ) {
wp_schedule_event( $timestamp, 'daily', 'myplugin_cron_hook' );
// use wp_schedule_single_event function for non-recurring.
}
}
register_activation_hook( __FILE__, 'myplugin_activate' );
/**
* Unset cron event on plugin deactivation.
*/
function myplugin_deactivate() {
wp_clear_scheduled_hook( 'myplugin_cron_hook' ); // unschedule event.
}
register_deactivation_hook( __FILE__, 'myplugin_deactivate' );
/**
* Function called by the cron event.
*/
function myplugin_cron_function() {
// error_log( print_r( 'yes we have wp-cron', true ) );
wp_logout();
}
/**
* View all currently scheduled tasks utility.
*/
function myplugin_print_tasks() {
echo '<pre>';
print_r( _get_cron_array() );
echo '</pre>';
}