pre_get_posts action doesn’t work

There is nothing wrong with that code. It’s correct and working fine for me on a default installation.

Change to using the default theme. Does it work now? If so, then there’s something wrong with your theme.

Disable other irrelevant plugins. Does it work now? If so, then one of those plugins was interfering.

Eliminate the possible conflicts until the code works the way you expect it to work.