wp_insert_post_data: Limit number of Page but Post get affected

I would suggest one slight change to your logic as follows:

function set_post_to_draft_page_only( $data, $postarr ) {
    if($data['post_type'] == 'page') {

      if( wp_count_posts('page')->publish > 2 ) {
        $data['post_status'] = 'draft';
      }
    }
    return $data;
  }
  add_filter( 'wp_insert_post_data', 'set_post_to_draft_page_only', 99, 2 );

You were not returning $data if post type was anything other than ‘page’.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)