Toothache is a useful signal to us as we can visit the dentist who can try to fix any problems with our teeth. But what is the natural biological role of toothache? Does toothache make animals take action that helps them to deal with their dental problem?
Because your teeth evolved as a sensory organ.
The material teeth are made of evolved first in placoderms, it existed to sense the electrical current in the water around it, so it has to form around a nerve. in modern animals the nerve mostly functions in sensing stress and thermal stress on the tooth.
And because mammals are weird.
Teeth did not evolve to be permanent, they evolved to be lost and replaced, that is what everything that is not a mammal does. So having a nerve was not a big disadvantage (in say, reptiles) since that nerve would eventually wither and die as the tooth was lost. toothaches were not permanent they were a temporary irritation, and served do dissuade any behavior that caused them, like trying to eat food that was too hard, it was little different than the pain of thorn telling you not to grab sharp things.
Mammals are unique in retaining their teeth throughout their life so now a system shaped by evolution to be temporarily has been dragooned into something permanent. So now what would be a temporary irritation becomes a permanent thing when the tooth is damaged in mammals. Worse permanent teeth means things like stress on the teeth is even more important since you are stuck with damaged teeth so mammals actually make the nerves bigger. The addition risk of a toothache is not an issue because mammals are stuck with that risk anyway because they retain the tooth. The earliest mammals did not have long lifespan so the risk of a debilitating toothache was minimal, however we their descendants live for decades, so a structure evolved to last a year or two now has to survive for decades and it just fails sometimes. Evolution can only change what it has it cannot throw out a problematic system and start over from scratch, so it often gets stuck with such haphard thrown together solutions (kluges) And we unfortunately have to pay the price in this case
Abscesses happen easily in teeth and they are close to the sinuses and the brain. It's important for animals to be wary of permanent tooth damage and abscesses that can lead to death.
Good teeth are crucial for survival and reproduction, to avoid starvation. Nerves prevent animals from being careless with their teeth.
Teeth get chipped from cracking nuts, seashells, marrow, hunting, fighting, kocking a slack jaw, gritty food.
The nerves are pretty well tuned to guide the mammal for safe and proper use of his teeth.
I would guess that humans and "smarter" animals (animals with strong cognition, culture learning etc.) figured out that some kind of oral hygiene and diet helps against toothache. However, it turns out that apparently animals don't get tooth decay and don't need special oral hygiene.
In any case, nerves in teeth cause pain when a tooth breaks. This allows animals to develop an avoidance response in the future: "This kind of nut/bone/bark/root/seed/whatever may seem tasty, but chewing it last time hurt for a long time. Avoid it." It might even prevent any broken teeth in the first place if chewing starts to hurt. As @BryanKrause wrote in the comments, it serves the same purpose as pain anywhere else.