If your sf::View moves or isn't the same size as the window, then the pixel position of your mouse doesn't match anymore with the coordinates of entities inside your world.
You should use mapPixelToCoords (https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1RenderTarget.php#a2d3e9d7c4a1f5ea7e52b06f53e3011f9) to convert the position of your mouse to world coordinates.
(you may think you don't use any view, but there's always a default view)