In a bathroom, like with any other room, applying a coat of primer helps prepare the surface to be painted. Paint adheres better to primer than it does to a previous layer of paint or to drywall. This is especially important in a bathroom because the previous layer of paint is likely a semi-gloss or high-gloss paint, which is slick and does not hold new layers of paint as well as primer does.
If your bathroom walls are currently a dark color, and you are not planning to scrape the paint off before repainting, priming the walls is a good idea. The primer helps cover the old color and give you a clean slate on which to paint. The color you select will show up more vibrantly and in fewer coats if you prime the wall rather than paint directly over the old color.
A primary function of primer is to provide a smooth surface on which to paint. Most bathroom paints are semi-gloss, which is a type of paint that shows bumps or imperfections in the wall very easily. Therefore, applying primer first will create a smooth starting surface, which will lead to a smoother wall after you apply the paint.
A coat of primer will work with the new paint to help keep mildew from making its way into your walls, which is a major concern in the bathroom. However, it does not solve existing mildew problems. Therefore, before repainting your bathroom, scrub the walls with a diluted bleach solution, focusing on areas with visible mildew or where you have seen mildew in the past. Allow the walls to dry thoroughly before you apply the primer and paint.