There were many reasons for an invasion:
- punishing Naples for its support of the Knights of Rhodes, whom the king Ferdinand I of Naples sent two ships of reinforcements against the Turks, determining a burning defeat of the Ottomans
- creating a bridgehead for further operations in Italy, against Naples and possibly Rome (we have to keep in mind that the Sultan Mehmet II had conquered Istanbul in 1453, so the conquest of Rome was conceivable to him)
- making advantage of a peace treaty with Venice (1479) and of the division of Christianity in Italy (the Papal States and Naples fought the "War of the Pazzi" against Florence, 1478-1480)
These are however speculations.
In my opinion the intentions of Mehmet II were serious: the most important proof being that the commander of the expedition, Gedik Ahmed Pasha, was perhaps the best Ottoman general, with a crucial role in unifying Anatolia under Ottoman rule.
After conquering Otranto, because there was not enough food to sustain the occupying army, the Ottomans had to partially retreat to Albania, planning to start the operations again next year.
The death of the Sultan that same year however started a phase of instability, with his sons fighting over succession. Ahmed was forced to surrender as no reinforcements were sent. He never abandoned the idea of estabilishing a bridgehead in Italy, supporting one of Mehmet II sons, Bayezid, in return for support of his plan. Bayezid however did not trust Ahmed, and after having him imprisoned, he killed him in 1482.