English already had plenty of words for "forbidden." In 1777 it borrowed one from Tonga that also meant "sacred."
The borrowing came from James Cook's visit to Tonga. Cook noted that Tongans used the word for "any thing that is forbidden to be eaten, or made use of," as Wikipedia quotes him. In English it was written taboo. Etymonline says the OED credits Cook's account with the first English uses of both the noun and the verb.
The Tongan word is tapu, and it is not only Tongan. Linguists reconstruct a Proto-Oceanic ancestor, **tabu*, meaning "forbidden, off limits; sacred," with a sense of awe before spiritual forces. Its descendants run across the Pacific. It is tapu in Māori, kapu in Hawaiian and tabu in Fijian.
That double meaning is the heart of the word. Something tapu was set apart, whether it was holy or simply off limits, like the forbidden foods Cook described. Etymonline lists early English senses from "consecrated, inviolable" to "unclean or cursed," covering both ends at once.
A popular explanation splits Tongan tabu into ta, "mark," and bu, "especially." Etymonline reports it but says linguists suspect a folk etymology. The real source, on that view, is the Proto-Oceanic **tabu*.
In English the word drifted from religious restriction to social awkwardness. Today it covers topics people avoid at dinner as readily as sacred prohibitions. The older meaning survives in Tonga itself. The main island is Tongatapu, whose name Britannica glosses as "sacred south."
Cook's voyages brought English more than one Polynesian word. Etymonline dates tattoo, in the skin-marking sense, to 1769, also first recorded in Cook's writing.