Why is a 4 lb bag of sugar at the grocery store hard as a rock?
This happens when sugar is exposed to moisture. I've noticed this frequently happening when sugar is shipped on a refrigerated truck, then stored at room temperature, allowing some condensation to form. Whether the sugar is "damaged" or not depends on what you want to use it for. If you're going to put it in coffee, or otherwise dissolve it, it should be fine. If you want to sprinkle it over a donut, it probably won't work. 

Whether it's safe or not is a much harder question to answer, as it would depend entirely on how it was exposed to moisture. If it's from humidity or condensation, it should be fine. If it's from something being spilled or splashed on the bag, who knows?