"Ein Mädchen lernt."
because Mädchen and Kind is neutrum. Ein Mädchen, ein Kind. masculine is also ein. Ein Mann
It's like 'a baby' in English, referred to as 'it'. Gender isn't important when you stress young age.
There is not one rule that determines all gender. Sadly, you just have to memorize. It's a good way to try to remember though, but just like in English, the "rules" get broken all the time.
Mädchen is a diminutive for Maid. All diminutives (end in -chen) are neuter as I understand it. Everything ending in -ung is feminine. Der Junge isn't diminutive.
Ein is also neuter, not just masculine, and Mädchen is neuter, so it applies