Three people kindly wrote to me in response. The simplest comment was 'I would surmise she was born a Noy and then took her father's name when her mother married him or her step-father's name when her mother remarried'. In the context of the Will this would mean that Mary's mother (Samuel's daughter, whose first name we do not know) married a Noy. Noy is in fact a very rare name and I have not found an Irish marriage of a McIlhagga to a Noy. Nor, incidentally, have I found a marriage of a McIlhagga to a Napier.
The second person responded, 'My understanding is that "otherwise" on a Birth Certificate is a contraction of "otherwise known as"; for example, the child's parents were not married or where there was some doubt as to the real name. "Formerly" is used to indicate a known previous name such as might occur in the case of a widow or divorced woman'. I think it is very possible that Mary was born out of wedlock, though we don't know for certain.
The third person's response was the most comprehensive. 'In my experience this phrase is frequently used in cases of illegitimacy and is similar to "alias". If that does apply in your case I would interpret the likely meaning as Mary was born to a mother whose maiden name was Napier and that she was born before her mother had married. Her mother subsequently married a Noy and Mary acquired his name. The phrase in your context is likely to have been used for the avoidance of any doubt. Of course it is entirely possible that the actual father before marriage may have been Mr. Noy'. The rest of this comment concerns parish registers.
Now of course we know that Mary's mother's maiden name was McIlhagga, not Napier. But this still leaves it open as to whether Mary's maiden name was Noy or Napier. The result is that I'm afraid we are not much further forward in knowing the surname of Mary's son John! Also, it is a mystery that Samuel left money to three sons-in-law but that none of them were a Mr. Noy or a Mr. Napier. Maybe this was because Samuel didn't approve of him, or simply that no such son-in-law was around. He might have died or even have abandoned Mary and her son. Either scenario would have given Samuel a good reason for naming Mary and John in his will.