Why my transistor switched when base was grounded?
You can do this to drive your motor.  The 1k resistor must be tuned based on your motor's expected current for a given voltage.  Usually you have a spec like 500mA@12V or something of the like.

Basically, to get the 500mA spec, you want collector current of 500mA.  The base current is always Ib=Ic/Hfe.

Tip122's Hfe is min 1000, so you get 500µA for Ib.  You know on a BJT that Vbe is 1.3V for Tip122 at 500mA (see plot in datasheet).  So if you have a GPIOs voltage of Vgpio, you have a voltage of Vgpio-2.5V across R1.

Using Ohm's law you can find out R1 => R1=(Vgpio-Vbe)/(Ic/Hfe).

For a 3.3V Gpio R1=(3.3V-1,3V)/(500µA) = 4K
For a 5V Gpio R1=(5V-1.3V)/(500µA) = 7.4K


Those resistor values are upper bound values to get your full 500mA.  You should be using values around those.







simulate this circuit &ndash; Schematic created using CircuitLab

Now for your question about what is going on, I can't answer.  It is not very clear about what you did and you look like you are mixing thing up a little.