SELECT 
  DISTINCT pc.category_id, 
  count(DISTINCT pc.product_id) as total_products 
FROM 
  cscart_products AS products 
  LEFT JOIN cscart_products_categories AS pc ON products.product_id = pc.product_id 
WHERE 
  1 
  AND products.product_id IN (
    19259, 19260, 19261, 20357, 20358, 20359, 
    20360, 20361, 20362, 21671, 21872, 
    21873
  ) 
GROUP BY 
  pc.category_id

Query time 0.00057

JSON explain

{
  "query_block": {
    "select_id": 1,
    "filesort": {
      "sort_key": "pc.category_id",
      "temporary_table": {
        "nested_loop": [
          {
            "table": {
              "table_name": "products",
              "access_type": "range",
              "possible_keys": ["PRIMARY"],
              "key": "PRIMARY",
              "key_length": "3",
              "used_key_parts": ["product_id"],
              "rows": 12,
              "filtered": 100,
              "attached_condition": "products.product_id in (19259,19260,19261,20357,20358,20359,20360,20361,20362,21671,21872,21873)",
              "using_index": true
            }
          },
          {
            "table": {
              "table_name": "pc",
              "access_type": "ref",
              "possible_keys": ["pt"],
              "key": "pt",
              "key_length": "3",
              "used_key_parts": ["product_id"],
              "ref": ["lillyshop_lillyshop.products.product_id"],
              "rows": 1,
              "filtered": 100
            }
          }
        ]
      }
    }
  }
}

Result

category_id total_products
429 3
540 3
1154 6