I beg to differ with the previous answers.
It has nothing to do with the etymology/origin of these words. It's a phonological phenomenon. The <gn> in English is weird; when it comes at the end of a word, it lengthens the preceding vowel. When the <gn> is followed by a vowel, it shortens the preceding vowel in most cases.
Words that end with <gn> have the /g/ elided from them because English phonotactics does not permit the /gn/ cluster in the coda or onset of a syllable. However, it's a permissible cluster across the syllable boundary.
Whenever the <gn> comes word-initially or word-finally, the /g/ gets removed.
However, in word-medial position, the /g/ is pronounced when it's followed by a vowel (because it's allowed across the syllables and the following vowel splits it up into two syllables) and is not removed.
When the <gn> is followed by a vowel, the /g/ is usually pronounced except when some suffixes like -ing, -er and -able are appended. There may be exceptions, however.
When the <gn> is followed by a vowel, the /g/ is not removed:
- Signature → /ˈsɪɡ.nə.tʃə/
- Resignation → /ˌrez.ɪɡˈneɪ.ʃ(ə)n/
- Malignant → /məˈlɪɡ.nənt/ etc.
When the <gn> comes word-initially or word-finally, the /g/ is removed:
- Gnat → /næt/
- Gnome → /nəʊm/
- Campaign → /kæmˈpeɪn/
- Foreign → /ˈfɒr.ən/
- Sign → /saɪn/
- Malign → /məˈlaɪn/ etc.
All these words end/start with <gn>, so the /g/ is removed.
However, some suffixes like -able, -ing etc don't let the /g/ to be pronounced in these words:
- Signable → /saɪnəb(ə)l/
- Signing → /saɪnɪŋ/
- Aligning → /əlaɪnɪŋ/ etc don't have the /g/.