This is a VAST oversimplification...hopefully it makes sense.
Bacteria are constantly cleaning LR out. What happens is that LR and most sands are made of CaCO3 and phosphates naturally adsorb (chemically bond) to it. Then the good-guys that perform Nitrification/de-Nitrification for us engage in their 'bad habit'. Their bad habit is that they always want more phosphates (P) than they currently have. (It's a survival technique....they have to have enough P for themselves and for their offspring when they divide). They don't have mouths so they use acids and enzymes to literally dissolve the P right off the rock and sand. Unfortunately, bacteria measure their lives in hours, not days or years. Once they die, any P they contain becomes bio-available to other bacteria, re-adsorbing to CaCO3, or food for algae. (Luckily, it's usually other bacteria). This is why it's usually impossible to test for P with hobbyist test kits. Only after all other sinks are 'full' can P be tested for in the water column.
Have you ever turkey basted your rocks and thought to yourself, "There is NO WAY that my fish have pooped that much on my rocks"? You would be correct. Most of this detritus is produced by the bacteria that live on/in your rocks and if you don't have sufficient flow, you better be turkey basting your rock so your skimmer can remove it as it is supernutritious for algae. Now that bacteria have made a messy biofilm inside the porespace of your LR, and they keep dieing, mulm is produced. All of the descendents of the dead bacteria are still growing and they push filth, phosphates, mulm, sand, etc. to the surface of the rock where you should remove the detritus produced. Cooking does this in the dark for two reasons; 1) So that bacteria takes over as opposed to algae at this point, and 2) To kill any algaes that are already on the surface. Since it is done in a different tank or tub, there's never any additional P inputs. While I originally called the work that bacteria do a 'bad habit', it's actually a good thing as LR can always be cleaned out via bacterial action.
Cooking obviously requires judicious removal of this detritus and 100% water changes. For people who don't have a spare protein skimmer, this is usually accomplished by letting the rock cook with good circulation in the dark for a week, really shaking, dunking, etc. the rock in tub number 1 well, and then moving it to tub number 2. The following week, obviously there is brand new water in tub 1 and you do the shaking, dunking, etc. in tub 2 and move it back to tub 1. Cooking is done at normal tank temperatures.
Bacteria in sandbeds operate in the same manner. However, where is the detritus produced going to go? It's trapped on 5 sides and by gravity. Over time, the sandbed fills from the bottom up. Just like live rock, once you get to the surface, the detritus is supernutritious for algae.
Just like the Nitrogen Cycle, the Phosphate Cycle is going on 24/7. If you don't want algae problems, it is imperative that one minimizes P inputs and maximizes P exports 24/7 too. Waterchanges are great at removing Nitrates but they really aren't all that effective at removing P.