SELECT 
  cscart_products_categories.product_id, 
  GROUP_CONCAT(
    IF(
      cscart_products_categories.link_type = "M", 
      CONCAT(
        cscart_products_categories.category_id, 
        "M"
      ), 
      cscart_products_categories.category_id
    )
  ) AS category_ids 
FROM 
  cscart_products_categories 
  INNER JOIN cscart_categories ON cscart_categories.category_id = cscart_products_categories.category_id 
  AND cscart_categories.storefront_id IN (0, 1) 
  AND (
    cscart_categories.usergroup_ids = '' 
    OR FIND_IN_SET(
      0, cscart_categories.usergroup_ids
    ) 
    OR FIND_IN_SET(
      1, cscart_categories.usergroup_ids
    )
  ) 
  AND cscart_categories.status IN ('A', 'H') 
WHERE 
  cscart_products_categories.product_id IN (
    21567, 51083, 22715, 51082, 51085, 51081, 
    51088, 51087, 22713, 51086, 51089, 
    51090, 51092, 51093, 22714, 51091, 
    51095, 51096, 51097, 51098, 51100, 
    51099, 22716, 51103, 22712, 51105, 
    51102, 51101, 51123, 51122, 51121, 
    92, 49, 51129, 51128, 51127, 51126, 
    51125, 48, 51155, 51154, 51153, 51152, 
    21, 51158, 51157, 51156, 53, 51160, 
    51159, 51176, 51174, 51173, 51172, 
    91, 105, 50989, 46, 51370, 51371, 51372, 
    51373, 51452, 51453, 51496
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00232

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "167.94"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "29.80"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 383,
            "rows_produced_per_join": 15,
            "filtered": "4.00",
            "cost_info": {
              "read_cost": "40.09",
              "eval_cost": "1.53",
              "prefix_cost": "41.62",
              "data_read_per_join": "81K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`test_uchur_k`.`cscart_categories`.`storefront_id` in (0,1)) and ((`test_uchur_k`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`test_uchur_k`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`test_uchur_k`.`cscart_categories`.`usergroup_ids`))) and (`test_uchur_k`.`cscart_categories`.`status` in ('A','H')))"
          }
        },
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "test_uchur_k.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 18,
            "rows_produced_per_join": 29,
            "filtered": "10.81",
            "index_condition": "(`test_uchur_k`.`cscart_products_categories`.`product_id` in (21567,51083,22715,51082,51085,51081,51088,51087,22713,51086,51089,51090,51092,51093,22714,51091,51095,51096,51097,51098,51100,51099,22716,51103,22712,51105,51102,51101,51123,51122,51121,92,49,51129,51128,51127,51126,51125,48,51155,51154,51153,51152,21,51158,51157,51156,53,51160,51159,51176,51174,51173,51172,91,105,50989,46,51370,51371,51372,51373,51452,51453,51496))",
            "cost_info": {
              "read_cost": "68.94",
              "eval_cost": "2.98",
              "prefix_cost": "138.14",
              "data_read_per_join": "476"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
21 43,10,40M
46 42,18,391,40M
48 10,44,40M
49 10,43,40M
53 10,44,40M
91 44,9,40M
92 42,10,40M
105 44,6,394,40M
21567 394,42,40,29M
22712 42,40,7M
22713 40,42,7M
22714 42,40,7M
22715 42,40,7M
22716 42,40,7M
50989 394,42,40,29M
51081 40,42,7M
51082 42,40,7M
51083 40,42,7M
51085 40,42,7M
51086 40,42,7M
51087 42,40,7M
51088 40,42,7M
51089 40,42,7M
51090 40,42,7M
51091 42,40,7M
51092 42,40,7M
51093 40,42,7M
51095 42,40,7M
51096 40,42,7M
51097 40,42,7M
51098 40,42,7M
51099 40,42,7M
51100 40,42,7M
51101 40,42,7M
51102 40,42,7M
51103 40,42,7M
51105 40,42,7M
51121 10,42,40M
51122 10,42,40M
51123 10,42,40M
51125 10,44,40M
51126 44,10,40M
51127 44,10,40M
51128 44,10,40M
51129 44,10,40M
51152 10,43,40M
51153 10,43,40M
51154 10,43,40M
51155 10,43,40M
51156 44,10,40M
51157 44,10,40M
51158 44,10,40M
51159 44,10,40M
51160 44,10,40M
51172 9,44,40M
51173 44,9,40M
51174 9,44,40M
51176 9,44,40M
51370 391,18,42,40M
51371 391,18,42,40M
51372 391,18,42,40M
51373 391,18,42,40M
51452 18,42,391,40M
51453 18,42,391,40M
51496 40,33M