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’.