Disconnecting the battery before charging is important to protect the vehicle's electrical system and prevent damage to the charging equipment. When charging a connected battery, the voltage applied to the battery can cause a high current to flow through the vehicle's electrical system, which can overload and damage the wiring and electronic components. In some cases, it can even lead to a fire.
By disconnecting the battery, the charging current is isolated to the battery only, preventing any potential damage to the vehicle's electrical system. Additionally, disconnecting the battery reduces the risk of sparks and explosions, as there is no electrical power flowing through the battery terminals when they are disconnected.
If you are charging the battery in place on the vehicle, be sure to turn off the ignition switch. Leave the key in the ignition or otherwise activate the ignition switch (including accessories like lights or radio), and the battery will discharge again to power these circuits as soon as the charger is disconnected.