You’ll need to echo back your results in PHP.
foreach($category_detail as $cd){ echo $cd->cat_name; }
Also you might want to consider putting something between each category. If you have categories/terms like Blue, Red, Green. Then how you are currently looping over them, it will print it back as:
data-category="BlueRedGreen"
Hope that helps!!