Usually, you want to replace the substrate every 1-2 months depending on the size of the container. You can also replace the substrate if there is a large amount of frass present on the surface.
Note: Do not replace 100% of the old substrate if the new substrate is from a different source. This is because the new substrate may contain bacteria and fungi that the larva is not familiar with. Leave at least 30% of the old substrate and put the new substrate on top so that the larva can slowly acclimate to the new substrate. Do not mix the two substrates.
Example of how I replace substrate:
32oz container full of poop after a month.
Take out the larva
weigh the larva to see its growth
Place larva in new substrate