No, a pocket holster doesnt attach to anything.
It works on friction. A good pocket holster will be cut with angles that will hang up in the pocket material allowing the pistol to be drawn easily, leaving the holster behind in the pocket. Some incorporate "sticky" material (not actually sticky.. but a rubberized or otherwise "tacky" material on the outside that helps it to "grip" the pocket as well.. but to be honest.. I see that on more cheap, less well executed designs than I do on quality holsters..
You want a holster around a pistol, no matter where you put it.. pocket or otherwise.. the holster protects the trigger/trigger guard.. which protects you from an accidental discharge.. carries the pistol at the correct angle for draw, in the right place for comfort, etc..
in the case of a pocket holster, it also keeps pocket lint, and other junk from getting into the pistol as easily.. keeping it both clean, and more reliable/functional.. and.. it helps to break up the outline of the pistol... if you dont know what youre looking at.. you wouldnt know that my little LCP is a pistol in my pocket.. its so flat and small that its pretty indistinctive to an untrained or unaware eye..
but.. in this holster:
even a trained eye, would have a hell of a time figuring out I had a pistol in my front pocket, as opposed to an iPhone..