The word bee, as used in spelling bee, is one of those language puzzles that has never been satisfactorily accounted for. A fairly old and widely-used word, it refers to a community social gathering at which friends and neighbors join together in a single activity (sewing, quilting, barn raising, etc.) usually to help one person or family.
The earliest known example in print is a spinning bee, in 1769. Other early occurrences are husking bee (1816), apple bee (1827), and logging bee (1836). Spelling bee is apparently an American term. It first appeared in print in 1875, but it seems certain that the word was used orally for several years before that.