I'll try to explain why 申し訳ございません is more polite and formal than ごめんなさい.

ごめんなさい consists of 御免(ごめん) + 為さい(なさい).
御免 is a the act of forgiving someone for their sin or mistake.

The 為さい here is the shortened form of 為さいませ, which is combination of 為さる (the honorific form of 為る[する] / 為す[なす]) and ませ (the imperative form of ます).

I mean, ごめんなさい ends up giving the impression that you politely order someone to forgive you for your sin or mistake.

On the other hand, 申し訳ございません consists of 申し訳(もうしわけ) + ございません.
申し訳 is the act of excusing yourself for something.
ございません is the most polite way of saying ない.
In a word, 申し訳ございません means you have no excuse for your sin or mistake.
This gives the impression that you admit your sin or mistake with sincerity.

As a result, ごめんなさい is used in casual settings whereas 申し訳ございません is used in formal settings.

>Degree of politeness and formality.
[most polite and formal] 大変申し訳ございません > 申し訳ございません > 申し訳ありません > すみません > ごめんなさい > ごめん > わるい [most impolite and informal]

Sorry for my blog post.