I found the problem. In another file of my project, I had imported pyautogui. It seems that pyautogui and filedialog.askdirectory() don't work well together — the import alone was enough to cause the dialog to freeze.
To solve the issue, I removed the global import pyautogui and moved it inside the __init__() method (or inside the specific function where it’s used). After this change, the folder selection dialog worked correctly without freezing.