I have DEMs in a folder like this

If I run gdal_merge -o out.tif *.hgt, it says
ERROR 4: `/*.hgt' does not exist in the file system, and is not recognized as a supported dataset name.
A similar thread asked this but the solution was to make a virtual file first and convert it to a .tif file. Merging all tiles from one directory using GDAL
Another similar thread https://trac.osgeo.org/gdal/ticket/2783#no1
gdalbuildvrt output.vrt *.hgtinstead? All 13 years old issues are not valid any more but the one that you found may be. – user30184 Nov 09 '21 at 14:47