To begin with, the definition of the word 'pocket' states that it is 'a small baglike attachment'. The reason for this particular definition is that the pocket was not originally sewn into garments as it is today. In fact, the first pockets were actually small pouches that hung from the belt where one could carry valuables and coins. The word itself comes from the Anglo-Norman word pokete and traces its roots to the Germanic root word 'bag', which is like the Old English word pocca. Therefore, the definition makes sense. 'Purse' and 'pocket', incidentally, have the same root word, only one is plural and the other singular.
In addition and worthy of note is the Scottish sporran, which is that nifty purse worn at the front of the kilt in traditional wear. The word sporran itself comes from the old Irish word sparán, which traces its roots back to the Latin word bursa, or 'purse'.
The First Interior Pockets
Since the pocket was on the outside of one's clothing, it was unfortunately subject to thieves or, more appropriately, cut-purses. More cautious people realised that if they kept their purses inside their trousers1, it would deter the pickpockets by making the theft more difficult.
But, there came a realisation: Although keeping one's pouch inside of one's clothes made it more difficult for thieves to get at the pouch, it also made it more difficult for the owner of the purse to get at the contents! And as the point of the purse in the first place was to make it easy to carry one's money, making it impossible to get at without embarrassment was not the greatest of solutions. Imagine, there you are, in the common market, and you want to buy yourself an apple. In order to buy it you must drop your trousers and expose your buttocks to the entire marketplace! (Note: In that day and age, not only did people not have interior pockets, but they also did not wear undergarments!)
The next step in the evolution of the pocket was what most people see them as today: a simple slit in the clothing. A slit cut into the side of your trousers (or by this time your skirt as well, as women have never been known for dropping their skirts in the marketplace... much) would enable you to reach into your purse with ease, while others would find it difficult to reach in without your knowledge and acquiescence. This act of the clothes slit caused a revolution in the shape and the angle of the opening in the purse, and it was around this time that they began to be called pockets.
The pocket flattened out, and became two pieces of cloth, one solid (the one at the back) and the other shaped almost like a 'U'. The pocket was also attached to its own belt, usually cloth at this time, and was often elaborately embroidered and decorated. You can still see some of these beautiful works of pocket artistry in museums that are dedicated to original period costumes.
However, if history had been left to the rich and carefree who had time to make and elaborate on the undergarment pocket, then our pocket history might have ended here. In many ways, that would have been a prettier solution. Imagine, pocket factories, we'd have them made out of all sorts of materials; after all, they were often right up next to the skin. Angora pockets, velour pockets, pockets made of polar fleece with silken tassels on the bottoms, etc...
The Modern Pocket
Looking to the modern pocket, we must go back to the trousers again. We are now in the late 1700s. Let's say it's 1784 before some poor soul gets sick and tired of having to remember to tie his pocket on every day before he gets dressed. Most likely, you know a person like this. This is a person who has problems remembering to put his trousers on before his shoes, let alone remembering to tie his pocket on before his trousers.
Yet, absent minded as he is, he is no dunce. Therefore, in a fit of pique, he asks his wife to sew the pocket right to his trousers so he will never forget it again. And suddenly, there you have it. The pocket. The real, true, ultimate pocket. The friendly pocket you and I know and love that has been our most intimate friend since childhood... warming cold hands or holding fluff, bits of string and useless notes from friends long past and best forgotten.
The pocket has gone through many changes since that fateful day. People have placed pockets in other places than the waist: on the knee, on the thigh, and at the chest (the infamous 'breast pocket'). People have even returned to the practice of inside pockets, again requiring people to pull down their trousers and moon the supermarket in order to get at their cash (though, thankfully, that is very rare).