If you had specific visit for Rameshwaram, then you could have managed to fly to Madurai, instead of Trivandrum.
But if you can not change now. it is OK.
As you land at Trivandrum, reach to Kerala State Transport Bus Depot, opp, Trivandrum Central Rly station.
For stay, you have nice hotels in Trivandrum near Trandrum RLy stn. Arya Niwas is...
more... good. Even you can have Rly Retiring rooms for stay of one day/night if you have train journey ticket.
You will get buses of tamilnadu state, marked S.E.T.U. That goes directly to Madurai. takes 7-8 hrs.
From Madurai, you get lot of state buses/private buses cheaply. Unless you have luxury a.c. in mind, you can choose bus ride.
Also from Trivandrum, there are three trains, but for you conecting train will be Guruvayur Chennai Express/16128 that arrivs Trivandrum @03.25AM. and reaches 1100AM in 7hrs.
Also there are trains from Madurai to Rameshwaram.