When switching from Mojave to Ubuntu, then back to macOS, I cannot reinstall Mojave
You used the startup keys ⌘+R which is for "Install the latest macOS that was installed on your Mac". Evidently, this was Mountain Lion which you installed without an Apple Id. The startup keys option+⌘+R are for "Upgrade to the latest macOS compatible with your Mac". This should be Mojave and I would assume no Apple Id would be required.