It's fairly easy to see that the problem says "the door is closed if the number has an odd number of factors, the door is open if it has an even number of factors" - where we define "the number of factors" of a number N as including all numbers that divide N, including 1 and N itself. For instance, the number of factors of 6 is four: 1, 2, 3, and 6.
Note the following:
If you multiply a number N by a prime p (where N is not already divisible by p), pN has twice as many factors as N. [It has all the original factors of N, and also p times each of the original factors of N].
If you multiply a number N by the square of a prime p (where N is not already divisible by p), then p²N has three times as many factors as N. [The original factors of N, p times each of those factors, and p² times each of those factors].
In general, if you multiply N by an odd power of p, you multiply the number of factors by an even number. If you multiply N by an even power of p, you multiply the number of factors by an odd number.
Note that 1 has an odd number of factors (1 is the only factor).
Any number N>1 is a product of prime powers. These may be primes themselves (6 = 2·3), squares of primes (98 = 2·7²), cubes of primes (56 = 2³·7), and so on.
Now if you express N as a product of prime powers, and every one of those powers is an even power, then N will have an odd number of factors. This is because you can get from 1 to N by multiplying by an even power at each stage; and as we've seen before, multiplying N by an even power means that the number of factors of N gets multiplied by an odd number (3 for squared factors, 5 for fourth-power factors, and so on).
But if even one of the prime powers in N is a prime itself (ie. the first power of p) or an odd power of a prime, then as you're going from 1 to N, multiplying by that prime power will multiply the number of factors of N by an even number (doubling it, if we're talking about a prime, quadrupling it if we're talking about a prime cubed, and so on).
So N can only have an odd number of factors if N is a product of even powers of primes — in other words, if N is a square number.
So the only doors that end up closed are the ones that are at square-numbered positions: door 1, door 4, door 9, and so on.
There are much shorter and more mathematical ways of explaining this result, but I wanted to make it clear in words without having to use TeX to write elegant symbolic formulae.