Surprisingly, it might not always be necessary,
However, to make one thing clear, if we are talking about caries, the tooth is not merely decayed, it is infected by bacteria.
Dental decay is due to the irreversible solubilization of tooth mineral by acid produced by certain bacteria that adhere to the tooth surface in bacterial communities known as dental plaque.
Microbiology of Dental Decay and Periodontal Disease (chapter of "Medical Microbiology")
There are multiple studies on what happens if not all of the infection is removed prior to tooth filling. For example The monitoring of deep caries lesions after incomplete dentine caries removal: results after 14–18 months
Interference in environmental conditions by partial dentine caries removal and tooth sealing arrests lesion progression, suggesting that complete dentine caries removal is not essential to control caries progression.
This suggests that as soon as the tooth is sealed, the infection doesn't spread deeper. One meta study reached the conclusion:
Based on reviewed studies, incomplete caries removal seems advantageous compared with complete excavation, especially in proximity to the pulp. However, evidence levels are currently insufficient for definitive conclusions because of high risk of bias within studies.
Incomplete Caries Removal: A Systematic Review and Meta-analysis
However, until this proves to be a very clear benefit with good evidence, the recommendation will be to remove the complete infection, for fear of it spreading deeper under the filling and/or the tooth getting weaker. Especially for not very deep infections, removing it all may be simpler and need less follow-up.