"Ein" is masculine but why "A girl learns" is correct?
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.
But it is so for boys? (Der Junge)
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
Why "A maid is learning" is wrong here?