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 (
    8305, 10896, 12820, 9551, 6903, 7680, 
    6902, 10017, 12825, 6901, 9837, 9792, 
    12819, 9786, 10452, 10313, 9492, 9789, 
    8352, 9788, 8332, 8358, 8328, 8121, 
    12826
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00088

JSON explain

{
  "query_block": {
    "select_id": 1,
    "nested_loop": [
      {
        "table": {
          "table_name": "cscart_products_categories",
          "access_type": "range",
          "possible_keys": ["PRIMARY", "pt"],
          "key": "pt",
          "key_length": "3",
          "used_key_parts": ["product_id"],
          "rows": 25,
          "filtered": 100,
          "index_condition": "cscart_products_categories.product_id in (8305,10896,12820,9551,6903,7680,6902,10017,12825,6901,9837,9792,12819,9786,10452,10313,9492,9789,8352,9788,8332,8358,8328,8121,12826)"
        }
      },
      {
        "table": {
          "table_name": "cscart_categories",
          "access_type": "eq_ref",
          "possible_keys": ["PRIMARY", "c_status", "p_category_id"],
          "key": "PRIMARY",
          "key_length": "3",
          "used_key_parts": ["category_id"],
          "ref": ["lillyshop_lillyshop.cscart_products_categories.category_id"],
          "rows": 1,
          "filtered": 100,
          "attached_condition": "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')"
        }
      }
    ]
  }
}

Result

product_id category_ids
6901 482M
6902 482M
6903 482M
7680 482M
8121 482M
8305 482M
8328 482M
8332 482M
8352 482M
8358 482M
9492 482M
9551 482M
9786 482M
9788 482M
9789 482M
9792 482M
9837 482M
10017 482M
10313 482M
10452 482M
10896 482M
12819 482M
12820 482M
12825 482M
12826 482M