It's not the lock on the file, it's the lock on the directory. The common file dialog in Windows changes the current directory of the process to the file that was selected, and a Win32 process holds a lock on its current directory. So when you open readme.txt in a particular folder, Notepad.exe's current directory is changed to and holds a lock on that folder.
This is also why so many people run into problems trying to eject removable drives -- because the last thing they did was to save a file onto that drive, and now Outlook or whatever the program that did the save has its current directory pointing there.
Wow, so notepad++ and vscode quickly change the cwd after opening a file via a win dialog?
It makes sense since 10 or so years ago it was often the case that one file explorer had a lock on a folder and another file explorer couldn't delete that folder. Then tools like processviewer.exe gave some insight.
This is also why so many people run into problems trying to eject removable drives -- because the last thing they did was to save a file onto that drive, and now Outlook or whatever the program that did the save has its current directory pointing there.