I think that manipulating the window's size should always be considered to be the last resort.
It is not very user friendly at all. It becomes a pain for users that want to place windows in specific places, for example.
The letter box view idea - as shown in the link above - is probably the best solution to this: the user gets the window they want and the program gets the ratio it wants and also can use the size of the window.
Additionally, this can be extended to use the window fully for user interface tools while still keeping the "sprite" at its own ratio (of course, the sprite could represent an entire game display).
With that said, you can use the viewport and view size from the letterbox code to resize the window, if you absolutely
must resize the window.
In addition, in the code you have shown, you have a ratio for both width and height. However, these are the ratios when compared to the other so both should never be used; one of them should be 1. Not that those constants are being used...
Also, you shouldn't need a sprite to resize the window. You could, for example, just resize the height of the window based on its width:
constexpr float ratioH{ 9.f / 16.f };
const unsigned int windowWidth{ window.getSize().x };
window.setSize({ windowSize.x, static_cast<unsigned int>(windowSize.x * ratioH) });