Because a varying density planet changes the problem, making it significantly more complex to solve algebraically (if not downright impossible, I'm not even sure if there is an algebraic mathematical representation of the density of the earth vs depth).
As a result of that, the assumption that the falling particle only experiences a force towards the inner sphere becomes invalid and you ruin the symmetry of the problem. The point is that by making these assumptions elegant algebraic expressions can be found. There are tonnes of things which would prevent this from working in real life, from the Coriolis effect to the atmosphere to the gravitational perturbations by the sun and planets, and of course the down right impossibility of drilling a hole through the center of the Earth. If you take real life factors into account it really doesn't work anymore. Abstraction is necessary to arrive to these nice expressions.
If all that wasn't enough, it's actually wrong since it uses Newtonian mechanics but I have no idea about how the Einstein solution works.
EDIT: For anyone stumbling here worrying what this discussion is about; it's not part of the course.
Yeah, you can actually still represent the gravitational force if you don't have a constant density. The solution would then depend on the nature of the density. If you naturally assume spherical symmetry (i.e. the density only depends on the distance to the centre of the Earth and that rotation of the Earth doesn't change the density), then you can use Gauss's law for gravity to work out the gravitational field (and hence force) at any point within the Earth.
Essentially, Gauss's law for gravity would say that g * 4pi*r^2 = -4pi GM(enc) = -4pi GM(total) * (r/R)^3. It still does this for a spherically symmetric mass distribution; a uniform density is just a special case of this.
g = -GM(total)r/R^3
It's the same as if you had a uniform density, so GeniDoi's assumption that it behaves as a spring would be justified if and only if you dropped the spring on the surface of the Earth but that condition is met here.
Then you'd just use R^3/T^2 = GM/4pi^2
Find that T^2 = 4pi^2R^3/GM
From the spring equation above, g = a = -GMr/R^3 = -kr/m where k = GmM/R^3
Period of a spring with spring constant k is 2pi * sqrt(m/k) = 2pi * sqrt(R^3/GM) = T
If the periods are equal, so are the half periods
The two equations are equivalent
So the half periods are the same
Essentially, this proof works for any spherically symmetric body and that's the most general case possible.