The answer in short: in statistical physics, thermal contact with environment is not necessary for fluctuations of the energy.
Now in detail: when we consider classical mechanical system, we can always (in every moment of time) ascribe some specific value of the energy $E$ to it.
When we work in the framework of statistical or quantum statistical physics, we allow the system to have some statistical distribution of microscopic states and hence a probability distribution of energies.
For example, suppose we have a quantum system with the Hamiltonian $H$, which has the eigenvalues and eigenvectors $H|\varphi_i\rangle=E_i|\varphi_i\rangle$. If the system has the density matrix $\rho$, then the probability to find the system in a state with the energy $E_i$ is $p(E_i)=\langle\varphi_i|\rho|\varphi_i\rangle$. Thus, we have a discrete probability distribution of energies, normalized to unity: $\sum_ip(E_i)=1$.
Another example: classical statistical system with the distribution function $\rho(p,q)$ [$p$ and $q$ are momenta and coordinates of all particles] and Hamiltonian $H(p,q)$. In this case, the probability distribution of the energy is $p(E)=\int dpdq\:\rho(p,q)\delta(E-H(p,q))$. It can be discrete or continuous, and is also normalized: $\int dE\:p(E)=1$.
Now consider the case of two interacting thermodynamic systems, being in thermal equilibrium with each other and having equal temperatures. Each of these systems has not a definite value of energy, but some probability distribution $p(E)$. In presence of intersystem interaction, the energy can flow back and forth between two systems. However, even if we suddenly switch off the interaction, each system (or, to be more precise, the corresponding statistical ensemble) will be left with its own distribution of energies.