The situations that enabled both of these very, very different leaders to arise in their respective countries was that of extreme disturbance caused by foreign powers.
In Gandhi's case it was the British Empire with its puppet Rajs, while in Hitler's case it was France's ridiculous war reparations demands and the banking interests that swept into Germany after the first World War's conclusion.
Both were essentially heroes of the existing regime who worked hard within the system with no real political ambitions that we know of—Hitler being an extremely decorated war hero, and Gandhi an extremely respectable lawyer—until the oppressive conditions slapped them so hard in the face they couldn't ignore it: Gandhi with the famous train incident where his company bought him a ticket he wasn't allowed to use due to being an Indian instead of a Brit, and Hitler with a return to the art scene after the war to find it overrun and hollowed out by foreign financiers.
There are many tragic parallels that can be learned from these near-mythological figures' lives and choices, and plenty of lessons for our own day. History is confounding.
Both wanted freedom for their people, even though the path and results were very different—especially once they attained power.