Pieces of music composed in a minor key sometimes end on a major tonic chord, and this was particularly common in the Baroque era (c. 1600-1750). A major chord used at a final cadence is called a “Tierce de Picardie” or “Picardy Third”. It can be used with either a perfect or plagal cadence. The tonic chord is written with capital Roman numerals.
Most of Bach’s chorales in minor keys end with a Tierce de Picardie (although there are small number of exceptions). This example is from Chorale no. 297. The key is G minor, but the chorale finishes on a chord of G major.