The characteristics of most animals are there for a reason. Either because they make them more likely to find food or get water (e.g. the long trunk of an elephant allows it to get water easily), to avoid getting eaten by other animals (e.g. chameleons can change their colours and so animals that like to eat them find it hard to see them), or to attract partners for mating (e.g. birds know how to sing beautiful songs for this purpose). I would say that they spikes on a hedgehog are a protection from predators, it would make it harder for other animals to catch and eat them!