You’re 100% right though, the key to retaining muscle mass while in a caloric deficit is consuming sufficient protein, or even over-consuming protein. In starvation situations muscle is next up after fat when getting consumed for energy but it seems like for the most part the muscle mass deterioration during significant weight loss periods is a natural side effect of the process and lifestyle required to accomplish it.
Secondary to that, the body needs some amount of glucose. The best option for that is stored glycogen. When those stores run out the body can enter ketosis which reduces but does not eliminate the need for glucose. Fat consists of three fatty acids joined by a glycerol part. Most of the energy is in the fatty acids, but the glycerol can serve as a limited supply of glucose. However that is not really sufficient, so to get more glucose, and the other option is breaking down protein.