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 (
    3866, 3867, 3868, 3869, 3865, 3870, 3872, 
    3871, 3876, 3862, 3863, 35730, 3864, 
    3861, 35731, 3873, 47984, 3874, 3884, 
    3875, 3880, 3877, 3859, 3879, 35729, 
    3881, 3860, 3883, 3882, 35859
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00261

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": 67,
          "filtered": 100,
          "index_condition": "cscart_products_categories.product_id in (3866,3867,3868,3869,3865,3870,3872,3871,3876,3862,3863,35730,3864,3861,35731,3873,47984,3874,3884,3875,3880,3877,3859,3879,35729,3881,3860,3883,3882,35859)"
        }
      },
      {
        "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": ["dev_db.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
3859 313,166M
3860 313,166M
3861 313,166M
3862 313,166M
3863 313,166M
3864 313,166M
3865 313,166M
3866 313,166M
3867 313,166M
3868 313,166M
3869 313,166M
3870 313,166M
3871 313,166M
3872 313,166M
3873 166M
3874 313,166M
3875 313,166M
3876 313,166M
3877 313,166M
3879 313,166M
3880 313,166M
3881 313,166M
3882 313,166M
3883 313,166M
3884 313,166M
35729 313,191M
35730 313,191M
35731 313,191M
35859 313,191M
47984 212,110,213,315,313M