You can run Build virtual raster
in batch mode and than define a pattern as for which layers or files you want to use. If your raster layers already have in their name some characteristics that allow you to group them together based on that, it's going to be easy. Often, DEM files are named after the extent/area they are located - something like gt30e140n90
for example.
If not, it's going to be more difficult as you don't have an easy way to access the groups you created in the layer panel, e.g. via QGIS expressions. They seem to be pure visualization tools to organize the layer structure. So you must use a workaround. I see onetwo (probably twothree) possibilities:
Rename all layers by adding for expample a prefix that represents the group - like
1_
for group 1,2_
for group 2 etc. As an alternative, you could also save all the layers from the same group to an own folder. Than you are able to run the tool to build a virtual raster in batch mode and select a pattern for the layer- or filename, using autofill/Fill down, as described here: https://courses.spatialthoughts.com/advanced-qgis.html#batch-processing, but using expressions to define the layer-/file-name pattern to select the ones you want to use.Save a copy of your project. Than delete all but one group. Create a virtual raster of all layers left in the project. Than re-open the saved original project, repeat steps 2 and 3. This might be the most time-consuming option I see: not very elegant, but efficient.
Using map themes instead of groups. I did not test it and I am not sure if it is going to work, just to give you an idea: define each group as map theme. Toggle visibility so that you see only one group, than create a new map theme. Repeat for all groups. Creat a Model using Model builder/Graphic modeler. There, you have the possibility to set map themes as input.