First, a general piece of advice: the human body is messy and complicated. It is rarely a good idea to learn physics concepts based on the human body. Instead, learn the physics concepts on simple systems first and then once you have learned the physics on the simple system you can come back to the human.
Here, let’s consider a spring instead of a human. Suppose that the spring is initially compressed, thus storing elastic potential energy. In its compressed state it exerts a force on the wall and since the wall does not move the spring remains compressed and continues to exert that force without losing any potential energy. So indeed, for a simple system we can clearly see that there is no work done and no energy loss in exerting a force.
Now that we understand the simple system, let’s go to the human. The difference between the human and the spring is that the human does not use springs for muscles. Forces are primarily generated in a muscle by using chemical potential energy, not elastic energy. This means that generating a force at constant distance requires continual use of chemical potential energy, unlike the case of a spring. Because no external work is being done, all of the energy goes to heating the muscle tissue (through repeated ratcheting of the actin and myosin and all of the supporting metabolic processes).
If you say it is lost to heat, then if the wall moves while I'm pushing with the same amount of force that would mean my body would produce less heat since now some of the energy I'm expending is being transferred to the moving wall, but how would my body know that the wall is moving so that it then produces less heat?
Yes, that is correct. Less heat will be dissipated in your muscles if you spend the same amount of energy in isometric exercise than in non-isometric exercise. Note that spending the same amount of energy is a strong restriction because that is not the same as exerting the same force for the same amount of time.
The body is very aware of whether or not the limbs are moving, both on a proprioceptive level and also on the actin and myosin level. We are poorly designed (in terms of efficiency) for isometric exercise (0% efficiency) and even worse for eccentric exercise (negative efficiency). On the level of the actin and myosin isometric exercise generates more heat for the same energy expenditure because the neighboring actin and myosin are randomly “jiggling” back and forth instead of pulling together.