That is an excellent question, that can be answered and explained in many ways.
Gandhi comes from a culture that accepts the concepts of "karma" and "reincarnation", as a part of the soul's (or 'atman') journey to 'Spiritual Awakening', in which it is made to go through "samsara" (the "cycle of birth and rebirth"), until the soul has repaid it's karmic debt. Having been conditioned by ego, the soul has lost it's original identity, in place of a world and material one, where it must endure the karmic lessons from the choices of each and every life time, over eons of time.
Everyone starts out in a different place in their advancement, in each mortal incarnation, is accountable to their own karma. When left unattended, the condition of the ego becomes stronger and more attached to the material realm, which makes it more difficult to see as a limitation to "Awakening", creating more karma to undo. This is why Eastern cultures have developed spiritual systems devoted to 'transcendence of the ego' to reach Spiritual Enlightenment, which have been preserved and passed down for thousands of years.
The Buddha mentions "rare are those who even hear of Enlightenment, even rare are those who pursue it; and rarest are those who become it". Despite what is known as "God/Self-Realization" being historically a statistical rarity, The Buddha says once a person chooses it as one's goal, it is destined to happen, in this life or the next, because the person will not be satisfied with anything less. Working on one's current karma by undoing the past, sets one up in a position to make Enlightenment a greater possibility in the current life time, or following ones.
Although, being born to the right karmic circumstances makes Awakening more likely, it does not guarantee it; as ever instant is presented as an opportunity to choose differently than we have in the past. This is why people born into poor worldly conditions can make major leaps in spiritual advancement, and people born to fortunate circumstances, can progress very slowly. All sorts of worldly things seem to come about in our lives that can hinder our spiritual evolution, but most of all is typically what we take things to be.
We live in a "Holographic Universe", where the 'entire whole' is contained in all of it's parts, and what is seen is dependent on the point of view. Thus, how we regard and frame our world determines what is possible in it. Even Jesus taught, in Matthew 7:2, "By the judgment you pass shall be passed on you and by the measure you apply shall be applied to you.". The Bible and Christianity do not have a specific word for it, but teaches the concept of karma as, "an eye for an eye", and "you reap what you sow".
There isn't anything "mysterious" or "magical" about karma. To explain the, 'why?', about anything would actually require knowing the entire history of existence, up to the moment. Because humans cannot know all there is to possibly know "karma" is used as a shorthand way of explaining, "the present is a result of the combined total of the past, influencing the future". "Karma" is to "freewill", as the "law of equivalent exchange" is to the "law of attraction".
The identification with, and attachment to, the ego, subjects us to materialism, because the ego operates from a position of 'lack', which is always motivated by 'gain'. Most people easily fall into materialism by ego conditioning, beginning with the identity with the "I", by which the soul becomes attached, with each life time. The material realm thrives on conflict; as the universe is an endless succession of violent collisions, eruptions, explosions and implosions. Life on earth is no exception, especially in the human domain.
Whether it is pleasure, knowledge, or fulfillment of purpose, we will be met with hardship and difficulty in seeking it out, because the ego misleads us into believing everything is a result of "doing" or having", rather than a consequence of 'being' and 'becoming'.