Following code is working fine for pages but how to add category id as well with pages in the following code.
add_action( 'template_redirect', function() {
if ( is_user_logged_in() || ! is_page() ) return;
$restricted = array( 250, 253 ); // all your restricted pages
if ( in_array( get_queried_object_id(), $restricted ) ) {
wp_redirect( site_url( '/user-registration' ) );
exit();
}
});