Because the correction mechanism is a bit stupid and doesn't understand language or what mistakes students are most likely to make -- e.g. that they would probably get the gender wrong more often than they would misremember the noun.
It seems to go from left to right, and if the gendered article could match any of the correct alternatives, it will expect that alternative, rather than considering that the following noun might be correct and the preceding article wrong.
In short, it doesn't know what you have in mind and so it offers some correction, which is not necessarily the "closest" in terms of how a human would think.
I wish it would take this kind of thing into account, but it doesn't, unfortunately.