Because you don't actually check whether an event has been generated and yet still access the event, which leads to undefined behavior where the event type has a random value which then may match the value of sf::Event::KeyReleased.
Read the official tutorial on how to properly handle events. ;)