Shakespeare was probably the first to use this expression, possibly describing the difficulty of being stuck in the pickling liquid made from brines and vinegar, used to preserve food.

    And Trinculo is reeling ripe: where should they
    Find this grand liquor that hath gilded 'em?
    How camest thou in this pickle?

    I have been in such a pickle since I
    saw you last that, I fear me, will never out of
    my bones: I shall not fear fly-blowing.