To be sure of getting a pair of socks of the same color, you must place yourself in the worst position.
When you take out socks without lookong (radomly), the worst scenary is that the first time you take out a sock of a color and in the second fime you take out a sock of different color. Then, the next time (the third time) you necessarily take a sock that match one of the two taken out previously, and so have a pair.
So, the answer is that you must take out three socks to be sure that you have a pair.