The phrase "bee in your bonnet" is an idiomatic expression used to refer to someone who seems to be obsessed with an idea or agitated about a concept. It might be uttered to describe someone who talks with great excitement about something they can't stop thinking about or discussing. For example, "She has a bee in her bonnet concerning the current pollution problem" describes someone who is troubled about pollution and is going to great lengths to discuss it with as many people as possible.
An idiomatic expression is a common descriptive word or phrase whose meaning is not to be taken literally. Although it is sometimes difficult to trace the original meaning of idioms, the origin of the English saying "bee in your bonnet" seems to date to the early 16th century, when Alexander Douglas wrote about someone being in bed with a head full of bees. Going to bed with a head full of bees would seem to describe someone who can't take his or her mind off something that he or she feels is important. It is speculated that the "bonnet" part of the phrase might have been derived from the large bonnet that a beekeeper wears. Hence, if a beekeeper were to have a bee in his or her bonnet, it would be very difficult for him or her to focus on anything else.
Robert Herrick used the idea in the poem Mad Maid's Song in 1648 when he wrote about a woman saying that she would look for the bee that bore her love away in the bonnet of the man whom she loved. Although this poem doesn't have the exact phrase "bee in your bonnet," it would appear to describe a person who is obsessed with something; in this case, it is love. After this poem was published, the phrase seemed to change to "bee in your bonnet" because of the alliteration of "bee" and "bonnet."
The exact phrase was published in Thomas De Quincey's Coleridge & Opium-eating in 1845: "John Hunter, notwithstanding he had a bee in his bonnet, was really a great man." It is not known whether this was the first time the phrase was published, but it would appear that the phrase was in use at the time, because the author assumes that the reader understands its meaning. Since then, the phrase "bee in your bonnet" has become a common English saying.