Shakespeare took the tradition of Mab, Queen of the fairies, and evolved her to become Titania, the fairy queen as a major character in A Midsummer Night's Dream
Queen Mab does not have a dramatic role in Shakespeare's Romeo & Juliet, but her mention serves to underline Romeo's immaturity in the context of relationships
During the course of the play Romeo faces several challenges and experiences that force him to grow up, and we see that by the time of his death he has matured significantly
1. Through lovers' brains, and then they dream of love
2. O'er courtiers' knees, that dream on court'sies straight
3. O'er lawyers' fingers, who straight dream on fees
4. O'er ladies' lips, who straight on kisses dream
5. Sometimes she gallops o'er a courtier's nose, and then he dreams of smelling out a suit
6. Sometimes she comes with a tithe-pig's tail tickling a parson's nose as a' lies asleep, then he dreams of another benefice
7. Sometimes she driveth o'er a soldier's neck, and then he dreams of cutting foreign throats, of breaches, ambuscadoes, Spanish blades, of healths five-fathom deep; and then anon drums in his ear, at which he starts and wakes, and being thus frighted swears a prayer or two and sleeps again