The threaded thingy with the locknut is an adjustment so the coupling locks onto the ball properly.
Sounds like it might need adjustment if it came off the ball.
Sit the trailer on the ball leaving the handle of the coupling in the up (unlatched) position, loosen the locknut, then use a screw driver to adjust the threaded thingy until the coupling is firm enough to just be able to lift off the ball, then tighten the locknut back up. With the coupling still on the ball, now drop the handle down into it's latched position, and test that it cant be lifted off.
Another method is to lock it all into place, then tighten the screw up until everything is snug (but not tight), then back the screw off about a 1/4 turn. Be careful to hold the screw in place while tightening the locknut.
PS- I'm not qualified to offer professional advice, and I'm happy to be learned more proper if someone knowledgeable offers better advice.