Let's begin with a small example and work up to larger ones. Noting that 1024 is a power of 2, we will restrict ourselves to the situation where the number of lockers is a power of 2.
For two lockers, the student opens locker 1, then when he goes back down the hall, he opens locker 2.
For four lockers, after the first trip down the hall, lockers 2 and 4 remain closed. On the return trip down the hall, the situation is essentially the same as in the case of two lockers (except the student is moving in the opposite direction and the lockers have even numbers). Therefore the last locker will be the second one (going in the reverse direction), which is locker 2.
For eight lockers, after the first trip down the hall, lockers 2, 4, 6, and 8 remain closed. On the return trip down the hall, the situation is essentially the same as in the case of four lockers, so the last locker should be the second locker (in the reverse order), namely locker 6.
For sixteen lockers, the last locker will be the sixth locker among 2,4,6,8,10,12,14,16 in reverse order, namely locker 6.
At this stage, it would be handy to have a formula for the kth locker among 2,4, ..., 2n (in reverse order). It's not too hard to see that it's 2(n + 1 - k).
Continuing on, for 32 lockers, the last locker will be the sixth locker among 2,4,...,32, namely locker 2(16 + 1 - 6) = 22.
For 64, it's locker 2(32 + 1 - 22) = 22.
For 128, it's locker 2(64 + 1 - 22) = 86.
.
.
.
For 1024, it's locker 2(512 + 1 - 342) = 342. Which is our final answer.
Note: Examining this argument more carefully shows the last locker opened in a row of 2n lockers is 2n - 2n-1 + ... + 2 for n odd, and 2n-1 - 2n-2 + ... + 2 for n even.