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 (
    7574, 6855, 8238, 20396, 10468, 7673, 
    9496, 13033, 7181, 9780, 9796, 9794, 
    10805, 9529, 18159, 9351, 6964, 10156, 
    10549, 11010, 11014, 11013, 11018, 
    6894, 6896, 12818, 12750, 20303, 20304, 
    20305, 19788, 20306, 20776, 20781, 
    20782, 20032, 19951, 23067, 23066, 
    18458, 18452, 18713, 13467, 22527, 
    23339, 21130, 9804, 21081, 9296, 19924, 
    6939, 8346, 21555, 21556, 21557, 21559, 
    21561, 21563, 21564, 21558, 21560, 
    21562, 13416, 6863, 7646, 18834, 18836, 
    13699, 13692, 20147, 18797, 6664, 7003, 
    7004, 7006, 7007, 7010, 7075, 7540, 
    7963, 8023, 8037, 8093, 8099, 8101, 
    8110, 8140, 8144, 8148, 8151, 8157, 
    8192, 8204, 8205, 8231, 9806, 10140, 
    10201, 10286, 10413, 10685, 11634, 
    11638, 12598, 12857
  ) 
GROUP BY 
  pc.category_id

Query time 0.00175

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": 105,
              "filtered": 100,
              "attached_condition": "products.product_id in (7574,6855,8238,20396,10468,7673,9496,13033,7181,9780,9796,9794,10805,9529,18159,9351,6964,10156,10549,11010,11014,11013,11018,6894,6896,12818,12750,20303,20304,20305,19788,20306,20776,20781,20782,20032,19951,23067,23066,18458,18452,18713,13467,22527,23339,21130,9804,21081,9296,19924,6939,8346,21555,21556,21557,21559,21561,21563,21564,21558,21560,21562,13416,6863,7646,18834,18836,13699,13692,20147,18797,6664,7003,7004,7006,7007,7010,7075,7540,7963,8023,8037,8093,8099,8101,8110,8140,8144,8148,8151,8157,8192,8204,8205,8231,9806,10140,10201,10286,10413,10685,11634,11638,12598,12857)",
              "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
386 4
410 1
431 7
447 6
452 2
453 7
459 1
460 3
483 3
490 2
507 4
510 2
524 1
565 4
587 4
589 3
608 1
634 1
752 1
784 1
786 4
819 3
844 1
892 14
942 1
1022 10
1067 1
1114 2
1121 11