The equation $\delta Q=nC_X\,dT$ can be applied to any material or system but always comes with an implicit assumption:
"I am heating (or cooling) the system via heating $\delta Q^{(\star )}$ under condition $X$ (e.g., constant pressure $P$ or constant volume $V$) and doing nothing else."
$(\star )$ I use $\delta$ because $Q$ isn't a state function we can take the derivative of.
That is, I'm not doing work on or extracting work from the system, and I'm not adding or removing mass.
In fact, since heating transfers entropy $S$ (with $\delta Q_\text{rev}=T\,dS$), this provides a useful way to define the molar heat capacity under condition $X$ as $$C_X=\frac{T}{n}\left(\frac{\partial S}{\partial T}\right)_X.$$
As you've noticed, an isothermal state can be maintained by heating an ideal gas while letting it expand, for example. The equation $\delta Q=nC_X\,dT$ is not valid in this scenario.
However, a useful alternative equation is $dU=nC_V\,dT$ (where $C_V$ is the constant-volume molar heat capacity), which always applies to an ideal gas under all conditions and processes. This equation tells us that we can maintain a constant temperature in an ideal gas if the heat input (output) exactly equals the work output (input).
(The presence of the term "constant-volume" in that equation often confuses new thermodynamics practitioners. It's just part of the name of the constant of proportionality; it doesn't place any constraints on any particular process. A more general equation for all systems is $dU=C_V\,dT+(\alpha TK-P)\,dV$, where $\alpha$ is the constant-pressure thermal expansion coefficient and $K$ is the constant-temperature stiffness; it just so happens that $\alpha=1/T$ and $K=P$ for the ideal gas, so the second term vanishes, and the only material property left is one with "constant-volume" in its name. See here for a much longer discussion of this point.)