Adding query string to multiple page urls in a WordPress function

In your second code you use undefined $post variable. Probably you meant a global $post, but as the second parameter to the filter is passed the ID of the post for which the link is created, and this does not necessarily have to be the current post of the loop.

Try this:

add_filter( 'page_link', 'nocfcache_query_string', 10, 2 );

function nocfcache_query_string( $url, $id ) 
{
    $ids = array (399, 523, 400, 634, 636, 638);
    if( in_array($id, $ids) ) 
    {
        $url = add_query_arg( 'nocfcache', 1, $url );
    }
    return $url;
}