What you are referring to is called "Churning".
Depending on where you are booking the ticket (eg, via a travel agent or directly with the airline) it is likely against the terms and service of the airline for either you or the travel agents. Doing it a small number of times will not be an issue, but if it's done repeated then you can expect the travel agent or the airline to take action - up to and including canceling your booking and not allowing you to make any future bookings.
There are a number of other issues, including the fact that the refund can potentially take several days or even several weeks to be processed and returned to your credit card.
And of course, this presumes that you can actually rebook at the same price - which as the flight gets closer is likely not to be the case.
Also note that the "legal" requirement you're referring to is only a legal requirement in the US. Also, airlines do not have to allow you to cancel the ticket, but may instead offer the ability to hold a ticket for 24 hours before purchasing it, in which case the cancel-with-24-hours requirement does NOT apply.