When a current carrying conductor is placed in a magnetic field,it experiences a force which produces a torque that rotates the conductor. This is because  any current carrying conductor will produce an electromagnetic field around it and so the magnetic field produced by the conductor will interact with the main magnetic field already present which exerts a force on the conductor. The direction of the force is readily given by Fleming's Left  hand rule
Suppose the sides of the coil(conductor) are AA' and BB' and the direction of current in the coil is such that the current enters along AA' and leaves along BB'. Let us assume that the coil experiences a torque in a counter clockwise direction when the coil side AA' is under  North pole of the main field. After rotating through half turn, the coil side BB' comes under  North pole.But as the direction of current in BB' is opposite to that of AA',the torque now will be in clockwise direction and as a result no unidirectional torque will be produced to rotate the coil.
Now suppose the direction of current in the coil side BB' is reversed (and automatically in AA' is also reversed),when it comes under  North pole,the torque will again be counterclockwise. And after completion of full turn,the current in coil side AA' will again be reversed  when it comes under  North pole so that a unidirectional torque is produced and the coil continues to rotate  counter clockwise. This automatic reversal  of the current is accomplished by commutator and brush gear and so the DC motor rotates continuously.