When you set the texture of a sprite, it also sets the sprite's size based on the size of the texture and its texture rectangle (part of the texture to use). When you comment out that line, the texture is zero in size when you set the sprite so the sprite stays 0x0 size until changed, which you don't do.
You'll find that if you set the texture after loading each time, this should fix your strangeness. Basically, the sprite needs setting to the texture when it has a size so needs to be loaded.
Actually, this is not strictly true because you can set the texture rectangle at any time and that can be used to size the sprite. So, a simple
sprite.setTextureRectangle(sf::IntRect(0, 0, width, height));
would set the size of the sprite in advance (it could replace the original loading of the texture, for example).
So, that's why.
However, there are some things you should really considering changing in this code, especially linked to your texture usage.
The big one is that you load texture from files every frame/cycle of the main loop. Loading from file is not only significant enough to slow down the program but also not necessary more than one: simply load before the main loop any textures you will need and then switch amongst them in the program.
Load them in before the loop:
sf::Texture texture0;
sf::Texture texture1;
if (!texture0.loadFromFile("0.png")) ||
!texture1.loadFromFile("1.png")))
return EXIT_FAILURE;
Switch between them in the program:
if (delay < 1) sprite.setTexture(texture0);
if (delay > 1) sprite.setTexture(texture1);