This effect which causes the non-directional movement ofa plant part in response to the touch of an object is called thigmonasty. The mechanism which takes place durng touch is explained below:
When disturbed externally, certain regions of the plant trigger a release of various chemicals, including potassium ions, within the body of the plant. These chemicals make water and electrolytes flow/diffuse out of the cell, resulting in a loss of cell pressure. This causes the cell to collapse, which squeezes the leaves shut.
This is a defense mechanism of plants which protects them from insects and other threats.