I bought a standard 24v transformer and attached a plug to one end so I can plug it into a standard outlet. Can I just mount it to the wall by the outlet? Should I leave some space between the back and the wall, or does that not matter? I’m concerned some portion of it may get hot, or needs some air by it, etc.
in mains electrical, wiring methods are everything. You're running smack into that right now.
What you were thinking of is this.
However for thermostat wiring, the above is a silly product, because generally speaking thermostat wiring is a permanent part of the building, and there'd be no reason to make it pluggable, and a lot of reason not to. Enter products like yours, which are designed to mount on standard 120/240V steel junction boxes, common as dirt in 120V wiring methods:
They're so common Amazon doesn't practically sell them, since every hardware store and electrical supply stocks them for about a dollar. As you can see, your transformer is made to be the lid of this.
However, you have it upside down. Code requires it be mounted with the AC power (black and white) wires on the inside, where they will splice to AC power wires also inside. The non-hazardous low voltage terminals are to be on the outside of the box.
Now, if your basement is unfinished, there's likely to be one of these junction boxes somewhere, with handy circuits behind it your electrician can tap. Alternately, she can fit one of these boxes at an appropriate location, and then use listed wiring methods compliant with the Electrical Code to bring 120V mains power to the box.
At that point, the electrician splices the transformer's 2 wires to mains power hardwired, fits the transformer as the box lid, tightens it down, and leaves. You use thermostat cable to take the 24V wherever you need to go. (or the electrician also could, obviously, and they're experienced at fishing wires through finished walls without wrecking drywall).
The key to this type is you let the thermostat wire do the traveling, you fit the transformer in a less finished utility space, crawlspace or basement where that makes sense. I would say that is also true of the wall-wart transformer you really want.
But you don't really want a wall-wart transformer, you want this thing, hardwired in and installed to code. Call an electrician, or learn proper wiring methods and fit your own box. DO NOT hork this thing together like you have been aiming to do so far.
The install sheet as seen here suggests that your transformer should be mounted to a 4" x 4" junction box. Once installed into a junction box, the transformer can be mounted in a manner approved by your local electrical codes. Typically, these are attached with machine screws to whatever metal enclosure your electrical source and controls are housed in.
Some possible issues with your setup: The black and white wires are meant to be wired directly into a 120v circuit with wire nuts or a junction block. This is usually done by running a section of EMT/flex conduit towards your power source to make a safe connection. In your case, you may also be able to stack your junction box on another existing junction box for power connection.
On the topic of heat, the screw terminals for your transformer are made to be on the outside of your junction box. Mounted in this manner, heat accumulation won't be an issue.
You can and it will work however, you will be installing it counter to the instructions from the manufacturer, a no-no. Additionally, your installation will not meet basic code parameters. If you could install new 4-square J box on the stud next to an outlet box, then just run a new wire/cable between the two boxes and hard wire the new transformer in the new box.