Why Do Hedgehogs Have Spines?

There are two different things people mean by this, and both are worth separating.

First, the backbone: hedgehogs are vertebrates, so they are born with a spine like every other mammal. An animal built low to the ground needs that supporting structure.

Second, and more likely what you are asking, are the prickly spines covering their backs. Those are modified hairs, and they evolved as defence. A hedgehog is slow and otherwise defenceless, which makes it easy prey, so instead of developing speed or aggression it went the armour route. When threatened it rolls into a tight, prickly ball, and any fox or badger that tries to bite or claw it comes away hurt.