Automatically catching mechanism for drop leaf table
Consider the wonderful world of the gusset. In its usual guise, it supports and strengthens a corner formed by a pair of otherwise weak members. Gussets are used in truss construction, building framing and many other locations.

In the simplest form, it's a right-triangle shape. For your application, one square side of the triangle would be hinged to the wall, with the other square side aligned with the shelf in the deployed position.



In the image above the green wall supports a yellow backing plate containing the hinge for the red/brown shelf (missing a hinge circle). The blue gusset is on a hinge visible in the top view. It's more practical in normal use to have the hinge at the top of the yellow in the drawing, but easier to draw at the bottom.

When the gusset is flush against the wall, the shelf will fall. The gusset should be either lightly spring loaded or the hinge tilted in such a way as to bias it to the open position. When the shelf is lifted, the gusset will reach the position shown in the side view, allowing the shelf to be supported.

Lifting the shelf slightly and pushing the gusset toward the stowed position begins the reversal. Once the gusset has a bit of angle to it, pressure of the shelf will assist the retraction. Wear surfaces could be protected by a plastic strip or panel on which the gusset would slide. Inexpensive poly cutting boards are handy for applications of this sort.

Piano hinges would provide reasonable strength as well as ease of alignment. The gusset need not be full depth in either direction, depending on the materials used.