Hide admin menu on update_option

OK, so you put your form in manu page callback and the code that is processing that form is also in that same function.

And you register your manu pages on admin_menu hook.

All of that means that when you process your form and change the value of your option, the menu is already registered. So it won’t change without refreshing the site.

To solve that problem, you’ll have to process your form before registering your menu.

And to do it in a way that respects best practices, you should also use admin_post_ hook to process your form. It could look something like this:

function test_sub_display() {
    ?>    
    <form method="POST" action="<?php echo esc_attr( admin_url('admin-post.php') ); ?>">
        <input type="hidden" name="action" value="my_test_sub_save" />
        <input type="text" name="test" />
        <?php submit_button(); ?>
    </form>
    <?php
}

function my_test_sub_save_callback() {
    if ( isset( $_POST[ 'test' ] ) ) {
        $value = $_POST[ 'test' ];

        if( '1' == $value ) {
            update_option( 'test_option', true );
        } else {
            update_option( 'test_option', false );
        }
    }

    wp_redirect( '<URL>' ); // change <URL> to the URL of your admin page
    exit;
}
add_action( 'admin_post_my_test_sub_save', 'my_test_sub_save_callback' );

PS. I’m not sure if it’s by design, but you show the form on submenu page, but that page won’t be shown if the option is set, so you won’t be able to change that option, if you hide the submenu.