Why does `url_to_postid` return 0 when testing `page_for_posts` Page?

The reason you get 0 back is because of the test at the end of the function:

if ( ! empty( $query->posts ) && $query->is_singular )
    return $query->post->ID;
else
    return 0;

The posts page doesn’t pass the is_singular test so 0 is returned.

If you have a URL and want to know if it’s the posts page, you can match it against the permalink returned from get_permalink when passed the page_for_posts option:

$page_for_posts_url = get_permalink( get_option( 'page_for_posts' ) );
if( $current_url == $page_for_posts_url ) echo 'this is the page for posts!';