Q:

Score analysis: Minuet in G Minor BWV Anh 115

The piece modulates from G minor to Bb major between the bars 12-14 but I don't know how to mark these chords as they have B natural in them, which doesn't belong neither to G minor nor Bb major. So, what function does it actually have?

A:

Hmmm, this is a little off the cuff, but I think it's probably easiest to look at mm. 12-13 (primarily 13) as a viio/ii or V7/ii in the new Bb key. That is to say, the B-nat is part of a secondary leading-tone or secondary dominant chord. I suppose it could just as easily be a viio/iv or V7/iv in the old key, and then you could call the iv a pivot chord like you already have. Probably it's six of one, half a dozen the other.

