They aren't allowed to have them, but they get smuggled in or tossed over the fences. Then the prisoners hide them. The authorities don't always know that a cell phone is hidden somewhere in the prison, and even if they do, it's extremely difficult for them to find it. Sometimes the authorities spend months looking for just one.
Here where I live they would take a basketball and cut it , put phones and other contraband inside, tape it shut, and toss it over the fence into the recreation area. To the guards it looked like any other ball. Prisoners would then get the ball and remove the contraband. I don't know how long that went on before they got wise...