ajax stopped working when not logged in wordpress

Try to output the debug query

Find fragment

$the_query = new WP_Query( array( 'posts_per_page' => 5, 's' => esc_attr( $_POST['keyword'] ) ) );
if( $the_query->have_posts() ) :

Replaced by

$the_query = new WP_Query( array( 'posts_per_page' => 5, 's' => esc_attr( $_POST['keyword'] ) ) );
echo (string)$the_query->request; 
if( $the_query->have_posts() ) :

Perhaps some hooks are triggered to find a guest. i checked – your code is working