I am not an expert now, but I think I once read that a lava tunnel is formed when lava (=magma at the surface) cools down at different rates: At the surface, the lava flow has already cooled, while in the interior, at depth, it is still flowing. This is how the tubes are formed (from lava, not from magma, by definition).