On the Hilbert property and the fundamental group of algebraic varieties