edit: LOL It looks like someone else posted an answer while I was writing mine.
You need to use the question tags to state the name and full version number of the story format you are using as answers can vary based on that information. You mention the :passageinit event so I will assume you are using one of the SugarCube 2.x releases because events aren't implemented in SugarCube 1.x
As explained by the :passageinit event's documentation that particular event (as well as all the other events) requires you to be using at least v2.20.0 of that story format, and because the current version of Twine 2 only includes the v2.18.0 release I will assume you have manually downloaded and upgraded your local version of SugarCube 2.x
By default each time the reader traverses between Passages the story format's engine makes a copy of the state (values) of all known story variables, the original is associate with the name of Passage that is being left and stored within the State History system, the copy is made available to the Passage that is about to be processed and shown.
From what I understand the :passageinit event occurs somewhere between the previous Passage being left and the next Passage's contents being processed.
Which tasks or events you can uses depends greatly on which HTML element the image will be a background to and what method you are using to assign the background image to the particular element, because some elements are destroyed and recreated during the Passage processing/rending process so you may not be able to assign them a background image until after the element has been recreated.
Based on your example I will assume that the img element with the image-background CSS class has been placed within the content of one of your Passage, if this is true then that element wont actually exist in any state until at least step 3.0 of the event/task overview and at that time the element will only exist in the content buffer so you would need to be searching for the element in it instead of within the page's DOM.
The element won't exist in the actual page' DOM until step 4.0, which is the earliest point when your current IF statement condition could possible return true.
I suggest you change your code to either:
a. use one of the step 3.0 methods and to search the content buffer for the element you want.
b. use one of the step 4.0 methods and use your existing code.
NOTES:
a. I didn't actually test your body element based styling code so even if you use the correct events/tasks there may still be issues with it.
b. I would suggest looking at using CSS rules to define each of your different backgrounds and assigning a CSS class to the target element and instead of assigning the background image directly to the element.