Parametric differentiation using first principles
Your relation is true in most cases, and it follows from the chain rule:
$$\frac{dy}{dt}=\frac{dy}{dx}\frac{dx}{dt}$$ $$\Rightarrow\frac{dy}{dx}=\frac{\frac{dy}{dt}}{\frac{dx}{dt}}$$ $$=\frac{\lim_{h\to 0}\frac{g(t+h)-g(t)}{h}}{\lim_{h\to 0}\frac{f(t+h)-f(t)}{h}}$$ $$=\lim_{h\to0}\frac{g(t+h)-g(t)}{f(t+h)-f(t)}$$
Note that $\frac{dy}{dt}$ and $\frac{dx}{dt}$ must exist and $\frac{dx}{dt}\neq0$ for this to hold. In some cases this will leave you without an answer despite $\frac{dy}{dx}$ existing.
For the case you mentioned, $\frac{dx}{dt}$ doesn't exist but oscillates on $[1,3]$, If we try anyway, we get:
$$\frac{dy}{dx}=\lim_{h\to0}\frac{\frac{\sin((0+h)^2)}{0+h}-0}{2(0+h)+(0+h)^2\sin(\frac{1}{(0+h)})-0}$$ $$=\lim_{h\to0}\frac{\frac{\sin(h^2)}{h}}{2h+h^2\sin(\frac{1}{h})}$$ $$=\lim_{h\to0}\frac{\sin(h^2)}{2h^2+h^3\sin(\frac{1}{h})}$$ using the small-angle approximation: $$=\lim_{h\to0}\frac{h^2}{2h^2+h^3\sin(\frac{1}{h})}$$ $$=\lim_{h\to0}\frac{1}{2+h\sin(\frac{1}{h})}$$ $$=\frac{1}{2}$$
This is reasonable but incorrect since from the chain rule we have $\frac{dy}{dt}=1,\frac{dx}{dt}\in[1,3]$ (if it existed), so the "average" $\frac{dy}{dx}$ should be $\frac{1}{2}$.
Basically, your relation is correct under the mentioned conditions, but can lead to false (but potentially interesting) results outside the "safe" conditions.