The sparking most people get is from filling the controller capacitors. If they were completely discharged (normal when the bike has no battery plugged in for a while, a few minutes to a few hours), then you can certainly get a spark when plugging in a battery, whether the controller is "on" or not, if main power is connected to it.
To avoid this, create a precharge circuit. There are dozens, if not hundreds, of threads about that, under precharge, pre charge, antispark, anti spark, etc., with many possible methods.