What tbone said above is correct. Here's the longer version...
Batteries leak when they are discharged. In some appliances, when the whateveritis is turned off the battery is still connected to the circuit. Even though the device may not be in use there may still be a small current draw which slowly discharges the battery. (I'm having flashbacks to 1980s transistor radios, so I'm gonna run with that image). So, we go on vacation, bring our little transistor radio, come home from vacation, unpack, put radio in a drawer, forget about it until next vacation. In the mean time, the battery slowly discharges whatever is left of its initial charge, and when discharged it starts to leak. We take the radio out to pack for our next vacation, it won't switch on, we open the battery compartment to a gooey, corroded mess. Throw radio away, buy new one at the airport.
Note that it takes many weeks or months for that to happen, it is not an overnight process. And yes, batteries not installed in a device will gradually self-discharge and leak but that is a much, much slower process (years).
On most guitars, when the cable is unplugged the battery is physically disconnected from the circuit (because the barrel of the plug is necessary to completes the battery circuit). When the cable is not present the battery is electrically in exactly the same state as it would be if it was physically taken out of the guitar. That means you are no more likely to have the battery leak in an unplugged guitar than to have the battery leak sitting on a shelf.
And BTW, Energizer batteries have a "No Leak" guarantee or they will repair your device at their cost.
In the worst case scenario, battery compartments are cheap and easy to replace and no other damage will occur to your instrument.