Most doubled nasal consonants in French either follow the orthography of their Latin ancestor (e.g. somme, from summum) or marked a nasal vowel followed by a nasal consonant, as in the modern word ennui.
Almost all of those nasal vowels have lost their nasality since the orthography was standardised but it was never adapted to reflect their changed pronunciation.
Old French vient /vɪ̪ent/ [vɪ̪̃ẽnt] vs viènent /'vɪ̪e.nənt/ ['vɪ̪ẽ.nənt] (/e/ is nasalised before a nasal consonant, but this is unconscious and not salient for native speakers, since nasal vowels only appear before nasal consonants as in modern English)
Middle French vient /vɪ̪ẽ(t)/ vs viennent /vɪ̪ẽ.nə(t)/ Nasal consonant are lost at the end of a syllable after vowels (as in vient) but not at the beginning of syllables (as in viennent). This makes the nasality of the vowel audible to native speakers, who modify the orthography of viènent to viennent to reflect the sequence of the nasal diphthong ⟨ien⟩ and the nasal stop ⟨n⟩
Classical French vient /vjɛ̃(t)/ vs viennent /vjɛ.nə(t)/. Nasal vowels lose their nasality before nasal stops, leading to the modern pronunciation and spelling discrepancy.