Hawthorne is playing with an image here. An imp is a little devil or demon. Another meaning might be a wild child. This symbol of the demonic just demonstrates a continued message that the author is trying to portray. He wants the audience to know that the rigid religiosity of the zealous Puritans was their downfall. Because Hester could find no grace or forgiveness for her crime, she is continually shamed by the vivid reminder of sin that is embodied in the fruit of her loin: Pearl.
What the author is directly saying in that last sentence is that although there is effort for Pearl's character to just be a child, at every turn, Hester sees the evil in her. Hester sees sin. Hester sees a little demon. The idea that the imp is trying to "mold itself into Pearl's shape" may be suggesting that the demon, the evil, and the sin are further infecting this child and taking her over.