I first learned this song in my elementary school music class back in the 1960s, and assumed it had been written by the Pilgrims and sung at the first Thanksgiving.
I've since learned that it originated in Holland, where it was written to celebrate the Dutch victory over their Spanish overlords in the Battle of Turnhout, January 24, 1597. This victory allowed Protestants to "Gather Together" in worship, something that had been outlawed by Catholic King Phillip II, of Spain.
The words were set to a well-known folk tune, and it is likely that the Pilgrims, who had spent time in Holland, would have learned the song there. They would not have sung it in church, however, as they sang only Psalms. Furthermore, if the Pilgrims did sing it, they would probably have sung the Dutch version, as it was not translated into English until 1894, and first appeared in an American hymnal in 1903. In 1937, when the Dutch Reformed Church finally decided to include hymns, rather than Psalms only, in their worship services, "We Gather Together" was chosen as the first hymn in their first hymnal.
The hymn has taken its place as one of the songs most associated with Thanksgiving in the United States. The lyrics are now most interpreted as referring to spiritual warfare, rather than the historical events of the war they were written to celebrate.