Originally a bonnet was a type of headgear for men as in a Scottish bonnet, because in the early Middle Ages women tended to wear veils rather than hats. But eventually the word came to apply only to women's hats and now only to babies' hats.
Looking at this picture, though, you are probably thinking, "I wouldn't call that a bonnet, I'd call it a tam", and for that you have Robbie Burns to thank. His poem "Tam o'Shanter" told of the titular farmer (non Scots would say "Tom of Shanter"), chased by witches on the way home from a pub. This kind of hat was typical of Scottish ploughmen at the time.
Scotch bonnet peppers, the fiery chilis used in Caribbean cuisine, are called that because of their similarity to a tam o'shanter (turn this picture upside down in your mind if you're having a hard time seeing it).