This law is based on the conservation of Energy where voltage is defined as the energy per unit charge. The total amount energy gained per unit charge should be equals to lost by energy per unit charge, ultimately we can say that energy conservation law used in kirchoff's second law.