Some of the other answers are close, but none of them quite nail it:
Aluminum foil is a low-emisivity material, meaning it radiates less heat. Like all low-emisivity materials it also reflects heat, but that is irrelevant in this context because the foil is directly touching your food to a significant degree, so the benefits of reflecting heat on the inside are negligible. If there was an air gap between the food and the foil, then that would significantly increase the insulation value and reduce radiant heat loss further.
As others mentioned, the primary insulation value of the foil is probably as a simple air barrier, to reduce convective and evaporative heat losses. Plastic or wax paper or any other airtight & moisture resistant material that is sealed tightly would achieve this same effect just as well, and without acting as a conductor to nearly the same degree.
The benefit of aluminum foil in comparison to these materials is the low-emisivity properties.
To explain this further, because it's somewhat counterintuitive: All else equal, low emissivity (i.e. shiny) materials radiate less heat. If you take a hot surface that is black and matte (not shiny/reflective), in other words a high-emissivity surface, let's say a steam radiator, and paint it with shiny metallic or white paint, it will immediately radiate less heat.
Even though the actual temperature of the surface will remain the same, or possibly get hotter, as measured by a thermocouple, it will radiate less heat, though the heat given off through convection and conduction will remain the same (excluding the non-radiative insulation value of the layer of paint, which is negligible).
In other words, if you touch it, it will feel just as hot, but if you stand a few feet away, you will feel less heat from the surface painted in low-emisivity paint.
This example is not hypothetical: it's actually common in New York city in older dream-heated buildings to see radiators that have been painted with shiny silver paint. This is because as windows have been replaced and building insulation improved (among other reasons), the radiators became oversized for the space, and painting them is a cheap way to effectively make them equivalent to smaller radiators.
It's worth noting that while all objects radiate heat, radiation composes an exponentially increasing proportion of the total heat given off as the temperature rises. For example a human only loses roughly 5% of their body heat through radiation (according to numbers I've seen), but a hot electric stove or a campfire emits a larger percentage of heat through radiation.
(Incidentally, this is why the benefits of 'space blankets' has almost nothing to do with the reflective / low-emisivity properties, and is mostly about simply blocking the wind and creating a trapped air space around your body. The marketing of these products is extremely misleading, as they may reflect 90% of your radiated body heat, but that is only a tiny and practically insignificant percentage of your total heat loss..)
Now, whether or not the benefits of reduced heat losses through radiation outweighs the increase in conductive and convective heat loss of aluminum foil due to its much higher conductivity, I don't know the answer to. It would be an interesting thing to test, and anyone with a toaster, some bagels, and a couple of thermocouples and meters could easily test this.. (anyone who's less lazy than me, that is..).
Which brings me to my final point. The other benefit of aluminum foil is that it easily crumples and has significant rigidity, so it can easily be wrapped around food and it will stay tightly conformed in place, without the need for tape or any other fastener. Combined with it being airtight, impervious to moisture, easy to work with (doesn't stick to itself unintentionally, for example) and fairly inexpensive, explains why it is commonly used.
Whether it is actually superior to plastic or other wrapping materials from a thermal perspective is an open question as far as I'm concerned. We should not assume that it is. It's not like deli workers are physicists.. The low-emisivity properties of foil are real, and a potential benefit, but I don't think that thermal properties are the only or even the primary reason that it is used.
Personally, if you get a foil-wrapped sandwich and want to keep it warm for a while, I recommend keeping it inside of a paper bag (and ideally, keep that paper bag inside of another container).