If you are using an SD card in the phone, it could also be that you have a bad or corrupted SD card. I had that issue on a 520 once. Changed out the card and it fixed everything.
If the phone has gotten wet, then there may be some sort of damage causing it. Could also be damaged or faulty in done other way.
Lumia 520 is known to have problems with battery fit. Especially over time.
Make a paper shim from about 3 folds of paper and insert it between the battery and the bottom of the well to push the battery up into the contacts. Make another and lay it on top of the battery to help the cover push the battery down into the well.