Of all the primary chords (I, ii, iii, IV, V, vi, vii°), the dominant (V) leads most strongly back to the tonic (I.) This is because the V chord contains both the supertonic, a tendency tone leading down to the tonic, and the leading tone, which (as the name implies) is a tendency tone leading up to it. Even stronger is V7, which includes the subdominant as a tendency tone leading down to the mediant.
During the Baroque Period, it became common practice to occasionally strengthen a chord progression by preceding a chord with its own dominant, adding accidentals as needed, essentially "borrowing" the dominant chord from another key signature. This is known as a secondary dominant.
The example below, "Ein' Feste Burg," is in the key of C, but in the third measure, you will see the V-chord (G major) preceded by a secondary dominant. The chord used is D7 (D, F♯, A, C), which is the dominant 7 chord in the key of G. Likewise, in the seventh measure, you will find the vi-chord (A minor) preceded by a secondary dominant, E7 (E, G♯, B, D), which is the V7 chord in the key of A minor.
Secondary dominants can fit anywhere into a functional harmonic progression as long as they precede the correct chord.