First of all one has to legally obtain the mantra through initiation (Diksha). This is the first step. Next, Purascharan, as prescribed, has to be done.
Without Purascharana, a mantra is stated to be devoid of any powers.
The Puras’charanam of Gâyatrî is repeating this twenty four lakh times
(i.e., as many lakh times as there are syllables in the Gâyatrî). But,
according to Vis’vâmitra, repeating thirty two lakh times is the
Puras’charanam of Gâyatrî. As the body becomes useless when the soul
leaves the body, so the mantra without Puras’charanam is useless.
Devi Bhagavata Purana, Book 11, chapter 21.
Some, further verses from KulArnava Tantram's 15th chapter:
Upadeshasya sAmarthyAt shri-guroshcha prasAdatah |
mantra-prabhAvAs-bhaktyatyA cha mantra-siddhi prajAyate || 13
Due to the power of the Upadesha (initiation), the grace of the Guru,
the effect of [the particular] mantra and due to devotion [towards the
deity] mantra siddhi is achieved.
Siddha-mantrAd guror-lavdho mantro yah siddhi-bhAga-bhavet |
Purva-janama-kritAbhyAsAnmantro vA shihgra-siddhidah || 14
Mantra siddhi is achieved for a mantra that is obtained from a Siddha
Guru. Or else, it is also swiftly achieved for a mantra that has been
practiced in the previous birth.
Diksha-purvam kuleshAni pAramparya-kramAgatam |
yo mantrah sa cha siddho na samshayah || 15
O Goddess of the Kulas, the mantra which is handed down in succession
through traditions and which is legally obtained through DikshA can
easily mastered without any doubt.
Therefore, few factors that ensure mantra siddhi are: the power of initiation, the nature or effect of the mantra itself, the grace of the Guru, whether the Guru himself is adept or not etc.
Also, if someone has advanced in the practice to an extent in their previous lives then that quickens the progress in the present too. And, devotion towards the Guru and deity also helps a lot.