To stitch someone up means to trick them so that they are put in a difficult or unpleasant situation, especially one where they are blamed for something they have not done. He claimed that a police officer had threatened to stitch him up and send him to prison. = frame, set up
To stitch up an agreement, especially a complicated agreement between several people, means to arrange it. Shiraz has stitched up major deals all over the world to boost sales. = secure