This was when the Israelites had taken the Ark of the Covenant into battle, and lost the battle, and the ark. All wasn't well for the Philistines, however. God sent them various troubles. The theology of the Philistines may not have been correct, but they knew that God was powerful (he had, among other things, removed the head of one of their idols without human help) and that they needed to do something to stop the plague and cancers (?) that he had sent to them. So they did their best to give Him glory.
Jesus had another take on the topic of glory, two in fact, in this passage:
I am reading the Bible through in a year, and was struck by the first two passages above, from the May 9th and May 8th readings (This post got stuck in my drafts for quite a while!). All quotations are from the ESV. (emphasis added)
Thanks for reading!