I saw that I need 12 candies to evolve my Pidgey, but I need 25 to evolve my Rattata and 50 to evolve my Zubat.
What influences that number? Is it the rarity of the Pokémon?
This is completely game dependent, and can be mostly correlated to the power of Pokemon you obtain after evolving your Pokemon.
Normal ones like Bulbasaur and Squirtle needs 25 evolution to evolve into Ivysaur and Wartortle, which are middle evolutions, which then need 100 candies to evolve into Venusaur and Blastoise. As there's a great difference between the power and moves of a Wartortle and a Blastoise, Niantic simply decided to set 100 candies for the final level of evolution.
Each pokémon has a pre-determined number of candies set by the developer. It appears to correlate to the strength of the pokémon you'll get after you evolve it, but that is something only Niantic can answer.
The amount of candies used to evolve a Pokemon correlates with the amount of evolutions the pokemon has and at what level that Pokemon normally evolves. Most pokemon with only 1 evolution need 50 candies. While Pokemon with 3 need 25 for the first and 50 for the second evolution. There seem to be some exceptions but i'm not 100% about those
Edit: Seems like strength or rarity also is a factor. Going with the above statement about the Magikarp needing 400 candies.
If there's 3 evolution forms then you normally need 25 and then 50 candies to evolve. If there's 1 evolution then you need 50 candies most of the time.
However there are exceptions, for example Makikarp requires 400 candies. The wiki actually shows you how many candies each pokemon needs to evolve.