Why Did German Tanks Use A Cannon Lock?

In World War 2, many German tanks were too big and heavy to move comfortably across difficult terrain. Their cannons or guns were too large, so to combat this engineers fitted the tank with a gun crutch or a lock. But why was this used?