The Phrase Finder writes that the expression indicates someone is obsessed with an idea and is in a state of agitation that someone would demonstrate if they did have a bee in their bonnet. There was an earlier expression “to have bees in one’s head” that was recorded from the 16th century. The first citation of the eventual expression located by the Phrase Finder was in “…the Reverend Phillip Doddridge Letters, 1790…”