Let $X$ be a real algebraic set, and let $Y \subset X$ be its singular set. In this question I'll focus on the analytic topology, so we can just imagine that $X$ is the zero set, in $\mathbb{R}^n$, of a certain polynomial $f(x_1, \ldots, x_n)$ with real coefficients. It's a classical result that $X$ can be triangulated with $Y$ as a subcomplex. Here is my question:

If $Y$ has codimension $d$ in $X$ (i.e. $X$ has dimension $n$ as a simplicial complex and $Y$ has dimension $n-d$) and $f: M^m\to X$ is a continuous map from a closed manifold of dimension $m\leq d-1$, is $f$ necessarily homotopic, inside $X$, to a map $g: M^m\to X\setminus Y$?

I rather doubt that this is true in full generality. I'd be quite interested in counterexamples (the simpler the better!) or any partial results of this nature.

Note that if $X$ were a smooth manifold and $Y$ were a submanifold, a positive answer to the question is one of the standard consequences of Thom's transversality theorem.

The question could be asked more generally for simplicial complexes $Y\subset X$. In this generality it's clearly false: let $X = Z \vee Z$, where $\pi_1 Z \neq 0$, and let $Y$ be the wedge point. Then $\pi_1 X = \pi_1 Z * \pi_1 Z$ and if $\gamma\in \pi_1 Z$ is non-trivial, every loop representing $\gamma*\gamma$ must pass through the wedge point $Y$. Here's a second question: is there an example of this form in which $X$ is actually a real algebraic set?

Finally, I'll mention that Lemma 2.5 of this paper gives a result somewhat along the lines I'm looking for, but just deals with loops in simplicial complexes (under somewhat strong hypotheses).