It's not completely clear if Italian word "troia" is etymologically related to the name of the city of Troy.
Treccani dictionary, gives this origin
lat. mediev. troia, forse voce espressiva che imita il grugnito del maiale
that is, it comes from Medieval Latin troia, that could be simply an expressive term that imitates the grunt of the pig.
Nevertheless, Grande dizionario della lingua italiana provides this explanation about the etymology of Italian "troia":
Dal lat. mediev. troia (nel sec. VIlI), solitamente fatto derivare dal nome di un piatto tipico della gastronomia romana, il porcus troiānus, un maiale arrostito e farcito di altri animali, successivamente chiamato
porcus de Troia e infine, semplicemente,
troia. Altri invece ritiene che tale preparazione gastronomica, menzionata solo in Macrobio (V sec.), non sia in realtà mai esistita e non rappresenti che un'immaginazione scherzosa; il termine troia sarebbe quindi una semplice formazione popol. di origine espressiva.
That is, it comes from Medieval Latin troia (in the VIII century). It's believed that it could derive from the name of a typical dish of Roman gastronomy, called porcus troiānus, a roasted pig stuffed with other animals, later called porcus de Troia and finally, simply, troia. If it were that way, Italian troia would be etymologically related to the name of the city of Troy because Latin troiānus comes from Troia (Greek Tροία). But this dictionary explains that others believe that this gastronomic preparation, mentioned only by Macrobius (V century), actually never existed and it's only fruit of a playful imagination; the term troia would therefore be simply a formation of popular expressive origin (and it wouldn't be related to the name of the city of Troy).
Trésor de la langue française explains the etymology of French "truie" in a very similar way:
Du b. lat. troja (VIIIe s. Gl. de Cassel, éd. P. Marchot, 80: troia: suu), d'orig. obsc. Il était tentant de rapprocher le mot de porcus Trojanus relevé une seule fois chez MARTIAL, Saturn., III, 13, 13, formé d'apr. equus trojanus, pour désigner un porc farci, bourré de petit gibier (porcum Trojanum mensis inferant, quem illi ideo sic vocabant quasi aliis inclusis animalibus gravidum ut ille Trojanus equus gravidus armatis fuit); de porcus Trojanus, aurait été tiré [porcus de] Troja; cependant, il s'agit plus vraisemblablement d'un mot de création plaisante que de l'appellation habituelle d'un mets, ERN.-MEILLET; FEW t. 13, 2, p. 314 b. L'examen de l'aire géogr. de truie (dom. gallo-rom.; Italie du Nord; de la Catalogne et Sicile), ainsi que la forme troga, relevée par DU CANGE, s.v. troga, suggèrent à G. BREUER, ds Z. fr. Spr. Lit. t. 87, 1977, p. 170, un étymon gaul. *trogja, formé du rad. *trŏgh « tirer » (dont sont issus, notamment en a. et m. irl. des termes signifiant « fertile, productif ») et du suff. gaul. -jā.
I will try to translate it:
From Medieval Latin troja (VIII century Gl. de Cassel, éd. P. Marchot, 80: troia: suu), of obscure origin. It was tempting to relate it to the expression porcus Trojanus found only once in MARTIAL1, Saturn., III, 13, 13, formed from equus trojanus, to designate a pig stuffed with other small animals, (porcum Trojanum mensis inferant, quem illi ideo sic vocabant quasi aliis inclusis animalibus gravidum ut ille Trojanus equus gravidus armatis fuit); from porcus Trojanus, it would have been drawn [porcus of] Troja; however, it is more likely a term of amusing creation than the usual name for a dish, ERN.-MEILLET; FEW t. 13, 2, p. 314 b. The examination of the geographic area of truie (Gaul-Roman domain; Northern Italy; Catalonia and Sicily), as well as of the form troga, noted by DU CANGE, s.v. troga, suggest to G. BREUER, ds Z. Fr. Spr. Lit. t. 87, 1977, p. 170, a Gaul etymology *trogja, formed from the root *trŏgh (which in French means "tirer" and from which come some Old and Middle Irish terms meaning "fertile, productive") and Gaul suffix -jā.
1.
I don't understand why Trésor de la langue française says Martial instead of Macrobius, since the reference to porcus troiānus and its relation to the Trojan horse appears in Saturnalia III, 13, 13 by Macrobius, from which comes the excerpt quoted in this source.