Sometimes Internet Recovery Mode will only boot into the OS which originally shipped with the Mac from the factory (it is annoying). If this happens, then just install Mountain Lion, then make sure Mountain Lion is fully patched & up to date so that you can download a macOS installer for a more recent version of macOS which is compatible with your Mac. You can find links to various macOS installers within this Apple article which also includes optional instructions to create a bootable macOS USB installer):
How to create a bootable installer for macOS - Apple Support
You can check which versions of macOS are compatible with various Apple hardware by using this article:
https://eshop.macsales.com/guides/Mac_OS_X_Compatibility
FYI, after erasing the drive the first time, you should have quit Disk Utility, then selected the "Reinstall macOS" option instead of rebooting.