Is there any theory behind this?
C, Cdim, Dm, G7
This is the true passing diminished chord. True, meaning there isn't a functional label to apply to it using Roman numerals. In fact in Roman numeral analysis you could leave the chord unlabeled to make clear it's only passing motion:
I ... ii V7.
C, Cdim, D, G7
This could possibly be called passing motion. But as @user59242 pointed out in their now deleted answer, the chord could be treated like a full diminished seventh chord and respelled...
Cdim: C Eb Gb (Bbb) respelled to
F#dim: C Eb F# (A).
That's fudging things a bit because it changes a diminished triad to a diminished seventh chord which isn't the exact OP. I still think it is valuable to point out this possibility, because you can find this kind of harmony.
With the respelling and filling out of seventh chords we get
C, F#dim7/C, D(7), G7 where both the
D7 have the same function leading to the
G7 chord. It's clearer with Roman numerals:
I viio43/V V7/V V7. It's a chain of dominants!
C, C#dim, Dm, G7
I viio/ii ii V7.
C, C#dim, D, G7
I viio/ii V/V V7.
In both cases the diminished chord is simply the leading tone triad of the
...I am a bit surprised about how similar they sound in context.
Indeed, it's surprising to hear all the options. Someone might think that change would not work. But there really is a simple explanation. From a functional harmony standpoint the variable part of the phrase is identified as pre-dominant harmony. Lots and lots of chords can fulfill that pre-dominant role. You can abstract that harmony to this:
I ... V7. In essence we are saying the phrase is just a move from tonic to dominant and the two pre-dominant chords are mere details. All four phrases are roughly equivalent.
I would point out this one important distinction. Something like
C, F#dim7, D7, G or
I viio43/V V7/V V. In that case the chords are similar, but the tonal center shifts to
G. Just keep in mind the movement to the
G chord can treat
G as the dominant of
C major or as a new tonic in
G major depending on the exact chord details. Functionally these are not equivalent.
...How to choose between Cdim and C#dim?
They all can sound good. That's really an artistic choice.