The Ramsey method in high-precision mass spectrometry with Penning traps: Theoretical foundations