If gases are not ideal at high pressures, why doesn't raising the temperature of a gas make it less ideal? I'm learning about ideal and non-ideal gas behavior in Chemistry, and my textbook and online sources say two things :

*

*Gases behave ideally at high temperatures and low pressures.

*Gases behave non-ideally at high pressures and low temperatures.

My question is : Doesn't increasing temperature lead to higher pressure (assuming rigid container), and thus the two general statements contradict each other?
Further, I understand why compressing a gas to increase pressure will lead to non-ideal behavior: the actual volume of gas molecules becomes noticeable compared to the volume of container. But, in a rigid container, raising temperature to increase the pressure of a gas doesn't exactly alter any volume dimensions, so why would gases act non-ideally in the latter scenario? (pressure is high so according to textbook gas is non-ideal)
 A: The reasons for nonideal behavior are different for the two scenarios you describe, and as such they do not cancel each other out.
The ideal gas law is an approximation that works well when the gas molecules are very far apart and don't collide very often. they are close together at low temperatures and high pressures and collide more often and with greater force at high temperatures, so the approximation doesn't work well in these cases.
At low temperatures and high pressures, the volume occupied by the gas molecules themselves cannot be ignored and must be included in the gas law. (Note also that whenever the temperature is such that the gas begins condensing into a liquid, the gas law fails completely and cannot be used.) At high temperatures, the molecules that strike each other experience an extra amount of repulsion which changes the compressibility law for the gas, and the ideal gas law begins to furnish inaccurate predictions.
Both these effects can be accomodated with more complicated approximations that include this physics in the model.
A: The main assumptions that are relevant here is that the size of the individual molecules is negligible compared to the average distance between them, and that the intermolecular potentials can be ignored. The first is invalidated if the molecules are too close to one another, i.e. if the number density of particles is too high. The latter is invalidated by some combination of high number density (since as the distance gets smaller, the strength of the potential increases) and low temperature (since even if the particles are close to one another, if the intermolecular potential is negligible compared to the average kinetic energy, it can still be ignored).
Indeed, a gas at high temperature and high pressure can still have ideal behavior as long as the number density is not too high. Many sources I've seen that state gases are non-ideal for high pressures are implicitly assuming that the temperature is fixed as the pressure is changed, and it is indeed true that for a fixed temperature gases become less ideal at high pressure. It's just that as you increase the temperature, the threshold pressure at which the gas becomes non-ideal increases as well.
