Insects which goes through a complete metamorphosis (holometabolism) has stage called pupa (pl. pupae). Insects that develops under ground or inside the tree makes a pupal cell (or cocoon, depending on species), a hollow room where they can safely pupate (becoming a pupa) and spend time as a pupa.
Depending on species, some may stay inside there for a week to several months before they pupate, and spend a week to several months to emerge (becoming adult insects). Then they may again spend a week to several months to exit the pupal cell to actively start feeding.
However, in some cases where a larva could not find a suitable location to construct a pupal cell, they may crawl up to the surface and just pupate there (picture above). This is not a normal circumstance, but you can make an artificial pupal cell, and move a pupa to it. We will discuss how you can construct an artificial pupal cell in near future.
Don't judge too quick though!
Larvae don't just dive into substrate and feed on like how you would see anime characters eating giant meat while digging through it! They make a small spacious room to stay and feed on, until they move on to another section of the container. When your larvae are ready to pupate, they will make pupal cell (usually on the bottom of container). When that happens, substrate surrounding the cell will have different color. You cannot see it very different on the picture above because I added clay on the bottom of container to aid it. However, if you only use substrate, and your larvae made pupal cells, then you will see surrounding substrate is being much lighter colored.