The answer to 'when to replace junction box' is that you should replace a junction box if it is damaged, outdated, or cannot safely accommodate the number of wires it contains. Junction boxes are essential for safely connecting and routing electrical wires in your home, so it's important to replace them when needed to prevent electrical issues or safety hazards.
Signs that a junction box needs to be replaced include visible cracks or damage, a box that is too small for the number of wires, or a box that is made of outdated materials like metal that can corrode over time. Additionally, if you are doing any electrical work that requires opening the junction box, it's a good idea to replace an older box with a newer, properly-sized one to ensure safety and code compliance.