The epenthetic n ([ŋ]) has been inserted for articulatory reasons. It eases the passage between the preceding unstressed vowel and the following consonant.
Epenthesis is the pronunciation of an unhistorical sound within a word. Consonants and vowels are usually inserted into words for the sake of ease. Epenthesis happens for a variety of reasons, some of them are:
- to prevent adjacent vowels in a hiatus, for instance, idea of is sometimes pronounced idearof, law and order is pronounced lawrand order (with an epenthetic r), in most non-rhotic accents to avoid a hiatus
- another reason is to simplify consonant clusters, for instance, most Indian English speakers pronounce 'school' ischool
- transition between a nasal and a fricative e.g. PRINCE-PRINTS merger
Some examples of epenthetic stops are:
- length is almost always pronounced lengkth, with an epenthetic k between the nasal [ŋ] and the oral fricative [θ] (Lexico gives a parenthetical k in its transcription)
- warmth and hamster are often pronounced warmpth and hampster, respectively (with an epenthetic p)
- thunder used to be þunor, the d is epenthetic.
- the n in passenger, messenger, nightingale
Epenthetic stops also occur at the end, for instance, the p in nope. 'Vowel epenthesis' also exists, for example, film is pronounced 'fil[ə]m' in most dialects.
Epenthetic nasal in 'nightingale'
According to Garner's Modern English Usage (p1003), the n in nightingale, passenger, messenger is epenthetic, though Garner doesn't explain the reason.
Donka Minkova in her A Historical Phonology of English also says that in late Middle English, there was a development of the epenthesis of /-n/ or [-ŋ] in the coda of unstressed syllables before the voiced velar stop /-g/ or the affricate /-d͡ʒ/ mostly in loanwords: harbinger, messenger, nightingale. She further says that “Dobson (1968: §438) calls the nasal 'a species of consonantal glide', easing the passage between the preceding unstressed vowel and the following consonant”.
Here's the relevant bit from Dobson:
'INTRUSIVE' [n] and [ŋ]
§438.The 'intrusive' [n] in messenger, papenjay, &c. and [ŋ] in nightingale and paringale 'equal' (<paregal) is a species of consonantal glide easing the passage between the preceding vowel and the following [ʤ] or [g], and is found chiefly in adopted words; it is perhaps, as has been suggested, associated with a desire to make weightier the middle syllable so as to avoid syncope . . . . It appears to develop at various dates from the thirteenth century (nightingale) onwards. In words in which it is an established feature of StE, e.g. nightingale and messenger, it is regularly shown by the ortheopists. Salesbury has potanger 'potager' and Portingal (but the latter must represent an OE variant; see OED, s.v.); Coles says pottinger is pronounced porringer. ...
[Dobson, E. J. English Pronunciation 1500--1700. 2nd ed. Vol. 2. Oxford: OUP, 1968.]
According to Dobson, the reason for the insertion of the nasal is to avoid syncope. Unstressed and coda-less syllables are rather prone to syncope. Syncope is the loss of segments from the interior of a word, especially unstressed vowel and sometimes syllables. For example, the unstressed, coda-less syllables in words like fam.ly, cam.ra, happ.ning, av.rage have been syncopated for many speakers. So the n in nightingale acts as a coda of the unstressed syllable and prevents syncope.
The Cambridge Handbook of English Historical Linguistics by Merja Kytö and Päivi Pahta says that this epenthetic n optimises the structure of the syllable by increasing the consonantal nature of the syllable:
One possible reason for this epenthesis is that the addition of a stop increases the consonantal nature of the syllable coda, thus optimizing the structure of the syllable (Blevins 1995). Consonant epenthesis can also occur wordinternally but with the same apparent motivation, compare English thunder–with /-nd-/ – and German Donner. A further instance of this type of epenthesis is the insertion of a nasal in an unstressed syllable before /ɡ/, i.e. /ˌV.ɡV/→ /ˌVŋ.ɡV/ as in ME nightigale → nightingale; ME messager → messenger(Jespersen 1909: 35ff., Dobson 1968: 1004).
In her Evolutionary Phonology, Juliette Blevins says that epenthesis is often considered to have an optimising effect on the syllable structure.
If I understand it correctly, this means that English syllables don't often end in short vowels like /ʌ ɪ æ ɒ/ etc., so the epenthetic nasal [ŋ] serves as the coda of the short vowel /ɪ/. According to another phonological rule Maximal Onset Principle, intervocalic consonants are syllabified as the onset of the following syllable as long as the phonotactic constraints of the language allow it. If 'nightingale' were without the nasal [ŋ], it would've been syllabified as */naɪ.tɪg.eɪl/, which would be awkward-to-pronounce. The nasal [ŋ] therefore acts as the coda of the second syllable, making the following syllable easy-to-pronounce. Also as far as I know, some languages disfavour word-medial onset-less syllables for some reasons. Now when [ŋ] becomes the coda of the second syllable, then the [g] becomes the onset of the next syllable:
Read the following sources for more discussion on the topic: