Extract post category except one category

You can simply loop over the categories that you don’t need. get_the_category() return an array of categories that the post belongs to.

With that in mind, you can do the following: (Just remember to change 21 and 41 to your desired ID’s)

$categories = get_the_category();
foreach ( $categories as $category ) {
    if( 21 ===  $category->cat_ID || 41 === $category->cat_ID ) {
        continue;
    }else{
        echo $category->cat_ID . '</br>';
    }
}