Part of the socket housing forms a leaf spring that pushes on the connector. This creates a lot of friction that keeps the connector in place. In addition the connector can have holes to accept these springs creating a snapping effect as the connector is pushed far enough. I found a good picture of this for USB-A [https://en.wikipedia.org/wiki/USB_hardware#/media/File:Male_and_Female_USB_Connectors.jpg](https://en.wikipedia.org/wiki/USB_hardware#/media/File:Male_and_Female_USB_Connectors.jpg) In addition to these visible ones the four conductors are also sprung to create more friction.
Note that this is handled a bit differently for each cable standard. Micro-USB for example uses latches in the connector. USB-C also have the leaf springs in the connector but no latches.
Latest Answers