Take a picture of the wires and where they are attached to.
Then take off the thermostat, and glue something like this backing plate over the hole, with caulk or Liquid Nails or whatever.
Don’t let the wires fall down behind the wall, tie on a string with a weight if needed.
Let the glue dry firmly before attaching the thermostat.
You can also use a cheap jumbo oversized switch plate, in plastic or metal.
Carefully drill new holes to mount the thermostat if they don’t line up.
The plates will have enough mojo to hold your thermostat, as long as the plate is well glued to the drywall.
Wall Plate for Sensi Touch Wi-Fi Thermostat in White