The answer to 'why is my junction box sparking' is that there is likely an issue with the electrical connections or wiring inside the junction box. Sparking in a junction box is a serious electrical hazard that should be addressed immediately.
Some common causes of a sparking junction box include loose or damaged electrical connections, exposed wires, overloaded circuits, or water damage. If you notice any sparking or arcing in the junction box, it's important to turn off the power to that circuit right away and call an licensed electrician to diagnose and repair the issue. Attempting to fix a sparking junction box yourself can be extremely dangerous and should only be done by a professional.