I'll add a complement to George Y.'s great answer.
technically the airlines could offer a free 24 hour "reservation hold" for the ticket instead of offering free cancellation to satisfy the DOT rules, but I'm not aware of any airline which is doing so.
Some airlines are indeed trying to (legally) trick customers by offering a free 24-hour "reservation hold" instead of 24-hour refund window.
For example, with Qatar Airways, if one purchases a flight ticket SFO->DOH, it will be typically be subject to a hefty cancellation fee, even if one requests the refund within 24 hours of the purchase. This is because Qatar Airways offers a free 24-hour "reservation hold", which allows Qatar Airways not to offer a free 24-hour refund period.
https://thepointsguy.com/news/24-hour-hold-mistake-story/ (mirror) covers this in one of their reader stories:
In 2011, the U.S. Department of Transportation introduced regulations requiring airlines operating to, from or within the United States to let passengers either hold reservations without payment or cancel bookings without penalty for 24 hours. What seems to have tripped Angelica up (and she’s not alone) is that each airline gets to choose how to comply. Most offer refunds within 24 hours of purchase, while some (like JAL) offer both 24-hour holds and cancellations, leaving the choice to customers. However, a handful of carriers offer holds exclusively, including Qatar Airways and Turkish Airlines (and American Airlines previously); once you pay, your fare is subject to the airline’s standard cancellation fees.
As a result, never automatically assume that one can always cancel a flight to/from the US within 24 hours of the ticket purchase.
Note from https://thepointsguy.com/news/24-hour-hold-mistake-story/ (mirror) that agencies may charge cancellation fees and the flight has to be at least 7 days prior to scheduled departure:
There are a few other stipulations:
- First, these regulations only apply to reservations made more than seven days prior to scheduled departure, though some airlines (like Delta and American) offer refunds for reservations made beyond that time.
- Second, only tickets purchased directly from the airline are explicitly covered; third parties like Expedia or Priceline may also offer cancellation and refund policies, but they aren’t backed up by the Department of Transportation.
As noted on https://thepointsguy.com/2017/06/aa-24-hour-cancellation-policy/ (mirror), some airlines have relaxed the 7-day requirements, and note that the actual number of days might also depend on whether the ticket is an award ticket:
When it comes to American’s main competitors, United currently requires tickets to be booked at least seven days in advance of departure in order to be eligible for free 24-hour cancellations, though enforcement of that rule is spotty. Delta is the most generous of the three legacy airlines, as you can cancel almost any Delta revenue ticket within 24 hours if it was booked directly with Delta. Award tickets are a different story, as Delta does not allow award ticket cancellations within 72 hours of departure.
(The quote is from 2016, the actual policies may have changed since then but the main takeaway is: always carefully check the policy of the specific airline you're using)
Another pitfall: the airline may charge a non-refundable fee to hold a reservation (if the airline allows full refund purchased tickets). E.g., from https://www.united.com/ual/en/us/fly/reservations/refunds/24-hour-booking-policy.html (mirror):
Any FareLock® fees paid to hold a reservation will not be refunded.