Variational Self-Consistent Theory for the Detuning of Beam-Loaded Cavities