Alright so this is not a definitive answer because I am not an expert in musical history but here we go:
The song was written in 1880 by Luigi Denza, a neapolitan composer, for the inauguration of the first funicular railway on Mount Vesuvius.It proved massively successful for the time, selling over a million copies within a year (for reference a million copies was the requirement for a golden record award in Italy during the 1970s).
This massive success led a few international musicians and composers to mistake the song as a neapolitan (and thus italian) folk song; notably Richard Strauss who, 6 years after the song's release, incorporated it into his Aus Italien, specifically the simphony's fourth movement which was called Neapolitan Folk Life (Neapolitanisches Volksleben). Denza even filed (and won) a lawsuit against Strauss.The german composer was not the only famous case, as Nikolai Rimsky-Korsakov from Russia made a very similar mistake by arranging Denza's song in an orchestral piece titled Neapolitan Song; this was 1907 so by this time the song had reached such a universal celebrity that the line between folk-author had become thin.
A question you may have at this point is: why does a neapolitan song represent italian culture worldwide? There are two main reasons
The first is quite simple; while the song's theme is indeed very neapolitan, being about the vesuvian funicular railway (moreover its lyrics are entirely in the neapolitan dialect), Naples was the city which saw the highest amount of emigration, even when the main source of italian immigrants abroad was the countryside. This led to many italian communities overseas to have a considerable neapolitan component (Naples also was and arguably still is the cultural capital of the Italian south).
The second has to do with music history: simply put, italian folk music was just as divided as the regions themselves.This fragmentation was still strong after Italy was united during the later half of the XIX century, a period in which regional folk music started becoming more popular. It was during this time (late XIX century) that local neapolitan music had a big surge of popularity which led to the creation of some of the better known italian songs, collectively known as a genre: La Canzone Napoletana (O Sole Mio is part of this genre for example).This massive popularity of local neapolitan music made it so that its influence would always be felt in the development of italian musical traditions.
Sources:Dizionario Biografico degli Italiani. Meloncelli, Raoul (1990).[transl. Biographical Dictionary of Italians]
The Harvard Biographical Dictionary of Music. Randel, Don Michael. Harvard University Press (1996).
Nicolas Slonimsky: Russian and Soviet music and composers. Slonimsky, Nicolas. Yourke, Electra Slonimsky (ed.). Routledge (2004).
Musica solida. Vita, Vito. Miraggi Editore, Torino, (2019).[transl. Solid Music]
Some Socio-Economic Emigration Differentials in Rural Italy, 1902-1913 in Economic Development and Cultural Change, vol. 7. McDonald, J.S. (1958).