When switching from Mojave to Ubuntu, then back to macOS, I cannot reinstall Mojave I had to switch from macOS to Linux momentarily for a short project and now that I'm done, I want to go back to macOS. Prior to installing Ubuntu on my Mac, I was running Mojave as my OS. I tried switching back to Mojave, but when I press ⌘R to enter recovery mode, only option you are given is Mountain Lion, so I installed it. Now when I tried going back to Mojave I am having the following problems:

When I click Get in App Store to download Mojave, and enter my password and email correctly I get following window:



Which is followed up by this pop-up:



Upon clicking LEARN MORE, it redirects me to this Apple Support site:

https://support.apple.com/en-us/HT208104 ("Learn about changes that might prevent you from editing your payment method or accessing the App Store and iTunes Store.")

But, my account has previously been used with App Store, and I also have all payment information down on my Apple ID. Any ideas how to switch back to Mojave?

I have tested this App Store issue by trying to install some other random app, so this truly is an App Store issue and not incompatibility problem of going from Mountain Lion to 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.