How to print the current post depth as update notification?

You should wrap your condition inside the function, rather than the function inside the condition (this will also prevent errors with code running too early as WordPress loads).

function my_admin_notice() {
    global $wpdb, $post;

    $depth = $wpdb->get_var(
        $wpdb->prepare( "SELECT post_parent FROM $wpdb->posts WHERE ID = %d", $post->ID )
    );

    if ( $depth == '0' ) : ?>

    <div class="updated">
        <p><?php _e( 'Depth is 0!', 'my-text-domain' ); ?></p>
    </div>

    <?php
    endif;
}

add_action( 'admin_notices', 'my_admin_notice' );