Quantum Simulation And Out-Of-Equilibrium Dynamics Of Quantum Gases In Optical Cavities