Recent research suggests that hibernating animals have solved the tradeoff between activating the immune system to ward off infection and conserving energy to survive the winter. As one of the researchers explained:
Our model, which is confirmed by field data, shows that torpor patterns generally seen in some hibernating animals may be an evolutionary adaptation to help protect them from bacteria that grow well in low temperatures.
So, long ago some mutations happened to create a hibernation behavior, and it worked. That is no big deal when you consider that mutations created the animal in the first place. Then some later mutations fine-tuned the behavior. This included the waking up to solve the tradeoff between fighting infections and surviving the winter. Again, not a big deal as mutations are constantly trying out new designs anyway. Once again the evidence confirms evolution.