Owners of Magento 2 stores have a lot of products and categories to maintain.
The admin may want to enhance which categories a product is assigned to in a Magento 2 store, change the categories, etc. in an ongoing attempt to improve the customer's shopping experience.
To begin with, one might need to get categories from a product in a Magento 2 to accomplish this. This report will also help with updating categories and goods in accordance with business needs.
This article demonstrates how to obtain a list of all categories from either the current product or another specific product.
Here you can find the solution to get categories from a product in Magento 2, Visit https://meetanshi.com/blog/get-categories-from-a-product-in-magento-2/