On removing the top metal case, we can have the first glimpse of the internal structure of the pen. A hollow metallic tube is attached with the bottom metallic casing of the Ball pen. The ink reservoir also called the refill with a blue colored plastic cap is placed inside the metal cylinder. The metal tube has dents on its surface which gets hooked with the internal structure of the top metal casing.
Inside this metal structure is a mechanical lock made up of plastic as shown in the image above. This lock has two half. The bottom half glued to the bottom metallic casing has a path cut out in its structure in the form of a vertical spiral. The top half pasted to the metal tube grips the refill at one end and has a knob at the other end which fixes itself in the vertical spiral path of the bottom half.
When the pen is to be used for writing, the top metallic body is rotated in clockwise direction. As a result of which the tip of the pen comes out and vice versa. This happens because on rotation the plastic knob starts moving in the vertical direction along the spiral path and hence the refill which is being gripped by the top half of the lock moves down.
This is one of the mechanism, some pens use the spring loaded push to on mechanism for the same purpose. Other may not have any mechanical motion rather a cap which covers the tip.