I’m trying to set the cookie to my site to button on click action ,it is working on when user logged in .When user logged out it’s not working

Your script uses jQuery so you should make sure that:

  • jQuery is enqueued on your site (it may be for logged-in users, especially admins, but not necessarily for logged-out users)
  • your script is added with jQuery as a dependency so jQuery is available when your script runs

I would use wp_add_inline_script() for this, like so:

function wpse310935_cookiebasedredirect() {
    ob_start();
    ?>
    jQuery(document).on('click', '#organisation', function(event){
      event.preventDefault();
      jQuery.cookie("site_changer", "organisation", { expires: 1 });
      window.location.href = window.location.href;
    });

    jQuery(document).on('click', '#young-professional', function(event){
      event.preventDefault();
      jQuery.cookie("site_changer", "young-professional", { expires: 1 });
      window.location.href = window.location.href;
    });
    <?php
    $my_js = ob_get_clean();
    if( ! wp_script_is( 'jquery', 'enqueued' ) ) {
        wp_enqueue_script( 'jquery' );
    }
    wp_add_inline_script( 'jquery', $my_js );
}
add_action( 'wp_enqueue_scripts', 'wpse310935_cookiebasedredirect' );