It happened to me while Using VS 2022 on Unity 2022.3.25f1 on Windows 10.
While I can't answer the "why?" entirely, after trying everything mentioned above (Restarting Unity and VS, Regenerating Project Files), as well as disabling/re-enabling the debugger, and removing/re-installing the Visual Studio Editor package (using the Package Manager), I found a workaround, that doesn't involve rebooting the PC:
Instead of clicking on the "Attach to Unity" button, I clicked on the menu: Debug/Attach Unity Debugger, and it worked!
The Debug/Attach Unity Debugger was mentioned above as a workaround for a missing "Attach to Unity" button but was an inspiration to try it as a solution.
So, I suspect the answer to "why?" has to do with a VS bug in the button functionality, since the actual functionality is OK.