Why does and object need to be in focus when taking a picture? As we know from junior high school physics, when an object is at twice of focal length f, it could form a same size real image. When an object is placed far from the lens, it would form a smaller image. But why, when we taking pictures using a phone, do we need to make something in focus? Does this mean the object is at the focal length of the lens? 
 A: For an object to be in focus, it needs to be a certain distance $o$ from the lens, while the lens, with a focal length $f$, is a distance $d$ from the sensor (film, etc) where
$$\frac{1}{f}=\frac{1}{d}+\frac{1}{o}$$
When the lens has a small aperture, the depth of focus is another factor: things that are "not quite the right distance" can still look in focus when the aperture is small (confusingly this is measured by the "f number" which is actually the ratio of focal length divided by diameter of the lens - so a large f number means a small aperture and a large depth of focus). 
You ask "why do we need it"? Perhaps that is best answered with a picture:

When the film / image sensor is in the red plane, light from a point on the object becomes a blob (circle - or whatever the shape of the lens is) on the image. When the sensor is in the green plane ("in focus"), the light is focused onto the smallest point and the image will be crisp.
When you have objects at different distances, sometimes one will be in focus and the other won't be - because a conventional (simple) lens cannot be focused on two different distances at the same time.
A: The specific answer to your question is that the lens must move relative to the sensor for the equation in the answer of Floris to hold (by changing d). This movement is usually done automatically by the camera and is called "autofocus". I has certain limits, certain precision, and doesn't always work perfectly. It cannot focus too close and often focuses on something else (like the background) rather than your intended subject. Better cameras have better autofocus of course.
