When used as a switch transistor is operated alternatively in saturation and cut off. In the above circuit we are giving a square wave input at the base terminal. Output is measured at the collector terminal.
When the square wave is at low level, the base current is zero and so the collector current is also zero. It appears as if resistance is shorted(cutoff). That is the input voltage is zero and the output voltage is equal to the DC voltage applied at collector resistance.
When the square wave is at high level,base current is such that we get maximum collector current(saturation). And the output voltage is nearly zero.
This is how we get 180° phase shift and this is how transistor works as a Switch.