I think you mean these two chords...
B diminished in the orange box and
C major in the blue box. You could simply label that
Am: iio6 III or I prefer
Am: viio6/III III to show the secondary dominant function of the diminished chord. That isn't a modulation, it's a temporary tonicization of
I posted an answer mainly to get the image label to show what you're asking about. You question made little sense to me when I first read it, because you cut off the key signature and the phrases appear to be a half cadence in
D minor and then a modulation and full cadence in
But, your question is "why?"
The two keys involved are
D minor and
Let's look at the chords on the strong first beats of the bars.
After the half cadence in
D minor, we get the
F major chord. That is the relative major of
D minor and would be a very common chord to play in the context of
The next chord
B diminished takes us to the
C chord. In the next key -
A minor -
C major is the relative major.
Then the proper cadence is essentially
Dm E | Am or
Am: iv V | i.
The harmony between the two cadences is basically working with the relative majors of the respective keys. So you could say the reason it goes to
C major is to get the relative major of the second key.