Try this.
Using for /r to iterate through all subdirectories and then Using %%~nxI to get the name and extension of the file.
set "folder=C:\stackoverflow\"
cd /d "%folder%"
setlocal enabledelayedexpansion
set "pattern=-"
set "replace=_"
for /r %%I in (*.txt) do (
set "file=%%~nxI"
ren "%%I" "!file:%pattern%=%replace%!"
)
endlocal