I am adding some additional details to the comment above, since somebody else asked me about this recently. Results about extensions of cohomology classes to all of $X$ from an open subset $U=X\setminus Z$ (or dually, proving that homology classes are obtained by pushforward from an open subset) are usually called *Purity Theorems* in algebraic geometry. In the setting that both $X$ and $Z$ are **smooth** and pure-dimensional, there is a very strong Purity Theorem in étale cohomology. One reference is Theorem 16.1 and Corollary 16.2, p. 108 of Milne's book.

J. S. Milne

*Lectures on étale cohomology*

https://www.jmilne.org/math/CourseNotes/LEC.pdf

Taking inverse limits of $\mathbb{Z}/\ell^r\mathbb{Z}$ coefficients and then inverting $\ell$, this gives a theorem in $\ell$-adic cohomology. If $X$ is defined over $\mathbb{C}$, this gives a theorem in singular cohomology with coefficients in a characteristic $0$ field by comparison theorems. Then using the Universal Coefficients Theorem, this gives the corresponding theorem in homology with $\mathbb{Q}$-coefficients, as you ask. However, that is all in the **smooth** case.

For low degree cohomology and its algebraic avatars (étale fundamental groups, Picard groups, Brauer groups, ...), there are other Purity Theorems that usually require much less than smoothness. One typical hypothesis is that $X$ is everywhere locally a complete intersection (LCI). Two great references are SGA 2 and Grothendieck's three exposes, "Le groupe de Brauer" in "Dix exposes sur la cohomologie des schemas". First, regarding purity for connectedness, i.e., $\pi_0$, there is $S2$ extension which is greatly generalized in Hartshorne's Connectedness Theorem. This says that if you remove a Zariski closed subset $Z$ from a pure-dimensional variety $X$ that is LCI, or even just $S2$, this does not change $\pi_0$ provided that $Z$ everywhere has codimension $\geq 2$ (regardless of singularities of $X$ and $Z$ beyond the $S2$ hypothesis). The hypothesis on the codimension is necessary -- just consider a quadric hypersurface of rank $2$ and $Z$ is its codimension $1$ singular locus.

The next result is purity for the étale fundamental group. The Purity Theorem is Théorème X.3.4, p. 118, of SGA 2.

MR2171939 (2006f:14004)

Grothendieck, Alexander

Cohomologie locale des faisceaux cohérents et théorèmes de Lefschetz locaux et globaux

Séminaire de Géométrie Algébrique du Bois Marie, 1962.

Augmenté d'un exposé de Michèle Raynaud.

With a preface and edited by Yves Laszlo.

Revised reprint of the 1968 French original.

Documents Mathématiques (Paris) 4.

Société Mathématique de France, Paris, 2005.

https://arxiv.org/abs/math/0511279

If $X$ is LCI and if the codimension of $Z$ is everywhere at least $3$, then the pushforward map of étale fundamental groups from $U$ to $X$ is an isomorphism. The hypothesis on the codimension is necessary -- just consider a quadric hypersurface of rank $3$ and $Z$ is its codimension $2$ singular locus, cf. Exercise II.6.5 in Hartshorne's *Algebraic geometry*.

The next Purity Theorem is for Picard groups (roughly an $H^2$ result rather than the $H^1$ result coming from fundamental groups). The first results were proved by Auslander-Buchsbaum for $X$ smooth (their famous theorem, later considered also by Serre, about factoriality of regular local rings). The LCI case was conjectured by Samuel and proved by Grothendieck: Théorème XI.3.13 and Corollaire XI.3.14 of loc. cit. Here the hypothesis is that $Z$ has codimension at least $4$.

The hypothesis on the codimension is necessary -- just consider a quadric hypersurface of rank $4$ and $Z$ is its codimension $3$ singular locus, cf. Exercise II.6.5 in Hartshorne's *Algebraic geometry*.

For Brauer groups (e.g., related to torsion in $H^3$), the first Purity Theorem is due to Grothendieck, Théorème 6.1, p. 135 of "Le groupe de Brauer, III".

MR0244271 (39 #5586c)

Grothendieck, Alexander

Le groupe de Brauer. III. Exemples et compléments.

Dix exposés sur la cohomologie des schémas, 88–188

Adv. Stud. Pure Math., 3, North-Holland, Amsterdam, 1968.

For $X$ in characteristic $0$, this theorem has a smoothness hypothesis on $X$, but the only hypothesis on $Z$ is that it everywhere has codimension $\geq 2$.

In case of a complex variety $X$ that is LCI but not necessarily smooth, Grothendieck made a number of conjectures at the end of SGA 2. Those were eventually proved by Hamm and Lê, and then reproved by Goresky-MacPherson using stratified Morse theory. One reference is the theorem on p. 199 of their book.

MR0932724 (90d:57039)

Goresky, Mark; MacPherson, Robert

Stratified Morse theory.

Ergebnisse der Mathematik und ihrer Grenzgebiete, 14.

Springer-Verlag, Berlin, 1988.

Because Goresky and MacPherson are proving such a general and precise version of the theorem, it is a bit difficult to parse. However, in the main case that $X$ is LCI, the point is that if $Z$ everywhere has codimension $\geq c$, then we can choose the general linear section $H$ of that theorem to have codimension $b=\text{dim}(X)-c+1$, so that $H$ is disjoint from $Z$. Then the integer $\widehat{n}$ of that theorem simply equals $\text{dim}(X)-b=c-1$ (**Edit** this is **not** $\text{dim}(X)-c$ as previously written). Thus, applying the theorem first to $X$ and then to $U=X\setminus Z$ (since $H$ is contained in $U$), the result is that the pushforward map on homotopy groups, $$\pi_i(U)\to \pi_i(X),$$ is an isomorphism for $i< \widehat{n}=c-1$, and the map is a surjection if $i$ equals $\widehat{n}=c-1$. By Hurewicz, the same thing holds if we replace $\pi_i(-)$ by $H_i(-)$. If you use $\mathbb{Q}$-coefficients and then use the Universal Coefficients Theorem, you get the analogous result in cohomology. You can also get cohomology result with torsion coefficients, e.g., for a complex variety $X$ that is LCI, for a Zariski closed subset $Z$ of $X$ whose codimension is everywhere $\geq 4$, the map of Brauer groups from $X$ to $X\setminus Z$ is an isomorphism. (Does anybody know a good example proving this codimension hypothesis is best possible? Quadratic hypersurfaces have trivial Brauer group, so that does not seem to work.)

Thus, for every complex variety $X$ that is LCI and whose singular locus $Z$ of $X$ everywhere has codimension $\geq c$, the pushforward map, $$H_i(X^{\text{smooth}},\mathbb{Q}) \to H_i(X,\mathbb{Q}),$$ is an isomorphism for $i<c-1$, and it is surjective if $i=c-1$.