After Hermione was caught becoming an unregistered Animagus, a punishment must be enforced. She believes a few weeks of detention would suffice, but as always, Dumbledore has other plans for her.
After being caught in her attempts of becoming an unregistered Animagus, Hermione is trapped in her form, as a way of punishment. Would she have preferred detentions every night with Filch? Of course. Instead, she was being forced to act as Severus Snape's familiar for the Headmaster's enjoyment.