Barrel distortion is a form of distortion (not to be confused with other aberrations). It is often found with shorter focal lengths such as the lens in a phone - especially those trying to get the wide rather than narrow angle field of view.
This distortion is also often seen with a single element lens, such as those associated with magnifying glass.
If a lens exhibits barrel distortion, it will be present at all focus distances. However, you will likely have more difficulty noticing the distortion on something that is distant than near by.
The way to correct for this is to use a more complex lens that, well, corrects for it.
(from HyperPhysics: multi element lenses)
The thing to realize here, especially with systems where the camera isn't the most part of it - its not really worth it to make more complex lenses. They're harder to manufacture, cost more, and aren't supposed to be great quality in the first place (price points).
For more complex lenses where barrel distortion exists, they are often either older designs where manufacturing and optical technology was lacking (we've been creating glass with ever higher refractive indexes and devising new ways to polish aspherical lenses), or the barrel distortion was the lesser of the evils of aberration that were being corrected for. Most consider astigmatism, chromatic, and coma aberrations to be more important to correct for than barrel distortion (which can be corrected to an extent in post production more easily than the others).
The specifics of the effect is that light at the edge of the lens bends more than it does in the center of the lens (ref). This is especially noticeable in lenses with a small diameter (that phone again).
The solution to this is to use a larger lens (larger sensors demand larger lenses which in turn have less barrel distortion inherent in the design). If possible, use an oversized lens (putting a full frame lens on a cropped sensor, or a medium format lens on a 35mm sensor). Another option is to use a longer lens and step back a bit. Neither of these may always be practical.
Fortunately, barrel distortion is rather predictable. Most post production programs will allow for a correction of it, if you know how much the scene is distorted. Shoot a photo of a checkerboard and correct that and you will know how to correct for all photographs with that lens in the future.