If we were to armchair diagnose Mercutio in his appearances throughout the play, we'd say he was in a "manic state," with his mind racing and his tongue doing a pretty good job of keeping up with it. If, in fact, you watch the Zeffirelli film version of the play, with John McEnery as Mercutio, you will see in the famous "Queen Mab" speech how this state exhausts and disorients him.
In the scene referred to in this question, this manic behavior is amplified, with the ribald byplay going back and forth between him and Romeo leading up to the teasing-crossing-the-line-to abuse of the Nurse.
Mercutio is clearly no fan of women, as evidenced in this list of epithets as he sees Romeo approaching:
"Without his roe, like a dried herring: flesh, flesh,
how art thou fishified! Now is he for the numbers
that Petrarch flowed in: Laura to his lady was but a
kitchen-wench; marry, she had a better love to
be-rhyme her; Dido a dowdy; Cleopatra a gipsy;
Helen and Hero hildings and harlots; Thisbe a grey
eye or so, but not to the purpose. Signior
Romeo, bon jour! there's a French salutation
to your French slop."
Therefore, it's very likely that Romeo's mooning over Rosaline has contributed to Mercutio's mood, which, unfortunately for him, is partially responsible for his death.