There is no direct connection from Madurai to Sabarimala. However, you can take the night train to Rajapalayam (RJPM) then take the taxi to Sabarimala. Alternatively, you can travel from Madurai to Sabarimala in around 4 h 22 min.
From Madurai Junction (MDU) night train to Rajapalayam (RJPM) then taxi to Sabarimala. 5 h 41 min ₹7,122. From Madurai taxi to Sabarimala. 4 h 22 min ₹6,848. From Madurai drive to Sabarimala. 4 h 22 min ₹2,028.