It's done to make a seam a little more attractive/decorative, or to add a stiffener to keep a shape. As mentioned above (one of the posts), piping can have a semi-rigid filler sandwiched inside. The effect is that there's a hidden 'frame' holding the bag into the desired shape.
The 'How?' is actually pretty simple - you can purchase commercially available piping, or....start with a strip of leather/textile and either simply fold, or fold around a filler, and glue it in place. Most piping will have relief cuts on the flat portion to prevent buckling around curves and corners. To install it, place it between layers with the right sides facing in, and sew.